Reputation: 5979
I need to remove item from multidimensional javascript object by value. For example, I have this objecť tree (screenshot contains only part): https://dl.dropboxusercontent.com/u/13057084/files-tree.png
I need to remove item by value of "file", so for example from tree on screenshot I need to remove file "9RuOxSPnTR-i_1.jpg".
I tried to use this:
$.each(files, function (index_folder,folder) { // foreach files as folders
$.each(folder, function (index_file,file_data) { // foreach folders as files (index_file = numeric index key of file)
delete files[index_folder][index_file];
});
});
Upvotes: 2
Views: 2570
Reputation: 47099
You use delete
to remove properties from objects and .splice
to remove elements from arrays:
> var o = {a: 1, b: 2};
> delete o.a;
true
> o;
{b: 2}
> var a = ['a', 'b', 'c', 'd'];
> a.splice(2, 1);
['c']
> a;
['a', 'b', 'd']
Upvotes: 2