Home >Web Front-end >JS Tutorial >Implementation code for cloning an array in Javascript_javascript skills
JS interview questions from a company in 2008, the position is javascript engineer (going to Google)
The interviewer asked me how to clone an array. At that time, I thought about it. The Object of js does not have a clone method, but the Object of java does.
Then how do you get a new array?
I answered at the time: Use a loop to push the elements of the source array into the new array in sequence. This is the simplest method, but obviously not the answer the interviewer wants.
Finally tell me: use the slice method of Array. The example is as follows: