I want to find the same object in an array and remove it from the array. Here is an example.
var previousSelectedWords = [{ 'id': 33, 'name': "美白", 'kana': "ビハク", 'type': 'new'}, { 'id': 3, 'name': "テスト", 'kana': "テスト", 'type': 'new'}, { 'id': 34, 'name': "免疫力", 'kana': "メンエキリョク", 'type': 'old'}];
var checkCurrentWord = { 'id': 3, 'name': "テスト", 'kana': "テスト", 'type': 'new'};
var foundWordIndex = $.inArray(checkCurrentWord, previousSelectedWords)
Looks like $.inArray doesn't work with objects. It always gives me -1
id and name, and kana can be the same, only type is unique.
-1, always.array.indexOf(object)does not work, you can't compare two objects, because they are never the same. You'd have to loop over all the keys and values in the object, and check each one, and see if they all match, and still the objects aren't "the same", but they do have the same keys and values, which is probably what you want to know.