JS, как удалить элемент из ARR2, но сохранить ссылку на ARR2?Javascript

Форум по Javascript
Anonymous
JS, как удалить элемент из ARR2, но сохранить ссылку на ARR2?

Сообщение Anonymous »

Что я хочу получить?let arr2=['aa','bb','cc','dd'];
let arr3=arr2;
arr2.remove('bb');
console.log(arr2);//['aa','cc','dd'];
console.log(arr3);//['aa','cc','dd'];
arr3.remove('aa');//['cc','dd'];
console.log(arr2);//['cc','dd'];
console.log(arr3);//['cc','dd'];
< /code>
Вот мои первые мысли о том, как получить:
first < /strong>:
Найти индекс элемента
second < /strong>
plocing position < /p>
let index=arr2.findIndex(item);
arr2[index]=arr2.at(-1);
arr2.pop();
//switch last one and ele of index



Подробнее здесь: https://stackoverflow.com/questions/794 ... ce-to-arr2

Вернуться в «Javascript»