current position:Home>Vue array push object problem

Vue array push object problem

2022-02-03 01:31:46 CSDN Q & A

img


When I come across such a problem , Before the test push Yes, you can add data , Yes, it works , After I don't know why push I've been reporting mistakes all the time , hold push If deleted, no error will be reported , I'd like to ask why ?? There is no substitute for push Method for adding objects to an array ?




Refer to the answer 1:

Array .push() Do you use console.log( Array ) Print this array , See what it is




Refer to the answer 2:



Refer to the answer 3:

push It's an array method . explain you Called Variable It's not an array [].push() . You can print it and see




Refer to the answer 4:



Refer to the answer 5:

This is because properties by null As a result of ,debugger Take a look , It's OK to write a check bar
Insert object into array push
Data splicing array concat / Deconstruct assignment [...arr]
Object replication Shallow copy Object.assign , Deep copy JSON.stringify + JSON.parse




Refer to the answer 6:



Refer to the answer 7:

Wrong meaning :

Non array variables call push Wrong method .

terms of settlement :

Call push Print out the object of the method
It is estimated that this variable has been changed in the middle of the code , It's not an array .




Refer to the answer 8:



Refer to the answer 9:

Your data is not an array , Where should you assign it to become undefined 了
stay push It is necessary to judge whether it is an array
arr instanceof Array && arr.push()




Refer to the answer 10:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030131436713.html

Random recommended