Anna University Plus
How to push data in javascript array - Printable Version

+- Anna University Plus (https://annauniversityplus.com)
+-- Forum: Javascript (https://annauniversityplus.com/forumdisplay.php?fid=1)
+--- Forum: JavaScript Array (https://annauniversityplus.com/forumdisplay.php?fid=6)
+--- Thread: How to push data in javascript array (/showthread.php?tid=15)



How to push data in javascript array - Berla - 11-21-2022

How to push data in javascript array

[].push(...items) – adds items to the end.
[].unshift(...items) – adds items to the beginning.

JS Array push() method adds one or more elements to the end of an array and returns the new length of the array.


Code:
const phone = ['iPhone','OnePlus']
phone.push('Nokia');