Remove element from multidimensional array

后端 未结 6 1831
情歌与酒
情歌与酒 2021-01-13 06:10

I have following multidimensional array:

{\"2\":{\"cid\":\"2\",\"uid\":\"2\"},\"1\":{\"cid\":\"1\",\"uid\":\"3\"}}

In this example i want t

6条回答
  •  温柔的废话
    2021-01-13 06:43

     var myObj= {"2":{"cid":"2","uid":"2"},"1":{"cid":"1","uid":"3"}}
    
    delete myObj['1'];
    
    alert ( myObj['1']);
    

    please notice there are Cross platform problems with delete :

    Cross-browser issues

    Although ECMAScript makes iteration order of objects implementation-dependent, it may appear that all major browsers support an iteration order based on the earliest added property coming first (at least for properties not on the prototype). However, in the case of Internet Explorer, when one uses delete on a property, some confusing behavior results, preventing other browsers from using simple objects like object literals as ordered associative arrays. In Explorer, while the property value is indeed set to undefined, if one later adds back a property with the same name, the property will be iterated in its old position--not at the end of the iteration sequence as one might expect after having deleted the property and then added it back.

提交回复
热议问题