Suppose you have an array with values in it:
let users = ["3" ,"4"];
And we want when new values are added to it:
let newUsers =[ "5" , "6"];
users.push(newUsers)
Delete previous values, not add to them.
???
I would appreciate it if you could help me.
3
Answers
Just clear the array:
You could use
splice
also:Note that if
newUsers
are bigger than about 100000 items you will get "Uncaught RangeError: Maximum call stack size exceeded". So you might want add item by item:If you plan to replace the content of the array more than one time, you could write a function for that:
But keep the Maximum call stack size (from the previous answer) in mind.
Just assign the newUsers variable to users and you are good to go.
This will work, but if you have any other requirements then please define too.