javascript push in specific index
arr.splice(index, 0, item);
//explanation:
inserts "item" at the specified "index",
deleting 0 other items before it
javascript push in specific index
arr.splice(index, 0, item);
//explanation:
inserts "item" at the specified "index",
deleting 0 other items before it
set element at index javascript array and create new array
const items = [1, 2, 3, 4, 5]
const insert = (arr, index, newItem) => [
// part of the array before the specified index
...arr.slice(0, index),
// inserted item
newItem,
// part of the array after the specified index
...arr.slice(index)
]
const result = insert(items, 1, 10)
console.log(result)
// [1, 10, 2, 3, 4, 5]
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us