← All references

ऐरे push/pop

array.push(item) / array.pop() / array.shift() / array.unshift()

ऐरे में वस्तुएं जोड़ें या हटाएं।

ऐरे push/pop

  • push(x) — अंत में x जोड़ें, नई लंबाई लौटाता है।
  • pop() — अंतिम वस्तु हटाएं, उसे लौटाता है।
  • unshift(x) — शुरुआत में x जोड़ें।
  • shift() — पहली वस्तु हटाएं, उसे लौटाता है।

ये सभी चार मूल ऐरे को बदलते हैं।

Example

const fruits = ["apple", "banana"];\nfruits.push("cherry");\nconsole.log(fruits);\nconst last = fruits.pop();\nconsole.log("Popped:", last);\nfruits.unshift("orange");\nconsole.log(fruits);