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
enter image description here
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];
});
});
2 Answers 2
Use splice:
files[index_folder].splice(index_file, 1);
answered Jun 21, 2013 at 7:40
Lian
2,3972 gold badges16 silver badges16 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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']
answered Jun 21, 2013 at 7:41
Andreas Louv
47.3k14 gold badges109 silver badges126 bronze badges
Comments
Explore related questions
See similar questions with these tags.
lang-js
if (file_data.file == "9Ru..."), or do you want to delete everything?