Why do you report an error when you call a method directly using []?

var arr1 = [1, 2]
var arr2 = [3, 4, 5]

// 
[].push.apply(arr1, arr2) // Uncaught SyntaxError: Unexpected token ]

// 
var s = [].push.apply(arr1, arr2)
console.log(arr1)
May.02,2022

is equivalent to

var arr1 = [1, 2]
var arr2 = [3, 4, 5][].push.apply(arr1, arr2)

the reason for the parsing mechanism is caused by not adding a semicolon.


[] only means to create a new array, which is an undeclared variable. If you don't declare it, you don't have to apply to open up storage space. You don't know where to store it and how to get it.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e5eb-2c41f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e5eb-2c41f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?