Deletion of objects and array elements

①Deletion of object attribute key-value pair You can delete

it directly with delete, or assign it as undefined

var goods = {barcode:"000", name: 'Coca-Cola', price: '3', unit: 'bottle'}

delete goods_info["000"] and goods_info["001"]=undefined The two deletion methods

delete are directly deleted, and undefined is to change the value of the key to empty for deletion.

②Array element deletion

(1) I know The subscript can be deleted by the splice(i,j) method.

i represents the index number of the element to be deleted (starting from 0), and j represents the number of deleted elements. The length of its array will change, and the corresponding index number will also change.

(2) delete: In this way, the length of the array remains unchanged, and the element to be deleted becomes null at this time.

But there are also advantages (the index of the original array remains unchanged)

. The author is also exploring the specific context of use.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327041232&siteId=291194637