Remove item from multidimensional array

I have the following multidimensional array:

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

In this example, I want to delete

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

From him. I tried all the solutions that I found on stackoverflow and could not get them to work. I am basically a php person, so can I skip something important here?

+3
source share
6 answers

Just use deletewith the appropriate property.

var obj = {"2":{"cid":"2","uid":"2"},"1":{"cid":"1","uid":"3"}};

delete obj["1"];

Pay attention to "around 1 to mark it as an identifier, not an array index!

, obj - , , [1]. , , , .

. , , .

+12
 var myObj= {"2":{"cid":"2","uid":"2"},"1":{"cid":"1","uid":"3"}}

delete myObj['1'];

alert ( myObj['1']);

, :

ECMAScript , , , ( , ). Internet Explorer, delete , , , , . Explorer, undefined, , - , .

+4

JavaScript does not have multidimensional arrays, only arrays and objects. However: delete theObject['1'];should work just fine

+1
source
var arr=[[10,20,30],[40,50,60],[70,80,90]];

for(var i=0;i<arr.length;i++){
    for(var j=0;j<arr[i].length;j++){
        if(arr[i][j]==50){
            arr[i].splice(j,1);
        }
    }
}

document.write(arr);
+1
source

Assign the variable Object(not Array) as follows:

var o = {"2":{"cid":"2","uid":"2"},"1":{"cid":"1","uid":"3"}};

Then do:

delete o['1'];

What is it!

0
source

You can use delete in javascript Example:

var x = {"2":{"cid":"2","uid":"2"},"1":{"cid":"1","uid":"3"}};

delete x['1'];

Also check this out:

Removing Objects in JavaScript

0
source

All Articles