Answer the question
In order to leave comments, you need to log in
How to make native JavaScript code compatible with libraries/frameworks?
The bottom line is this: the application has a lot of JS code that works with arrays, code like this:
for(var key in collection){
newCollection.push(JSON.stringify(collection[key]));
}
for(var key in collection){
if(typeof collection[key] !== 'object') {continue;} // добавлена проверка
newCollection.push(JSON.stringify(collection[key]));
}
Answer the question
In order to leave comments, you need to log in
all these "unnecessary" properties are added through the prototype, so you need to check:
for(var i in object) {
if (!object.hasOwnProperty(i)) continue;
// do stuff
}
var newCollection = collection.map(function (item) {
return JSON.stringify(item);
});
Use bare objects to store data.
To create such an object and strip it of all the inherited tinsel from the prototype, do this:
var collection = Object.create(null);
// теперь цикл по этой коллекции
for (var key in collection) {
// будет выдавать вам то что нужно без всяких проверок
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question