JS array delete specified subscript element JS delete object specified element

1. Delete the specified subscript element from the JS array

splice method——Array.splice(index,n)

Parameter semantic understanding: delete the n elements starting from the subscript index. (the following elements will move forward)

Note: splice will directly change the original array

let arr=['a','b','c','d'];
 
arr.splice(2,1);
 
console.log(arr); // ['a','b','d']
let arr=['a','b','c','d'];
 
arr.splice(0,4);
 
console.log(arr); // []
let arr=['a','b','c','d'];
 
arr.splice(0,2);
 
console.log(arr); // ['c','d']

 Reference: Delete specified subscript elements from JS array_Dahaozi's blog-CSDN blog_js array delete specified subscript elements

2. JS deletes the specified element of the object

var student = {
    name: '小明',
    sex: '男',
    age: 18
}

delete student.name;

console.log(student, 'student')

Reference: https://jingyan.baidu.com/article/ca2d939d00c8c8aa6c31cef4.html 

Guess you like

Origin blog.csdn.net/m0_65274248/article/details/126954323