javascript - Trying to sort an array of objects but splice is not a function? -
the global picture trying remove duplicates array of objects. objects same advertid , leadboxid considerd duplicates testing purposes checking advertids
i getting array sessionstorage , removing duplicates.
var testsort = function () { var events = []; events = sessionstorage.events; console.log("events unsorted"); console.log(events); (var = 0; < events.length; i++) { (var x = + 1; x < events.length; x++) { if (events[x].advertid == events[i].advertid) { events.splice(x, 1); --x; } } // add }
the console prints out events array such:
[{"module":"slick_module","eventtype":"swipe","leadboxid":"1565","advertid":"5653","length":"length of event","time":1462783354789,"posted":"postedstatus"},{"module":"slick_module","eventtype":"swipe","leadboxid":"1565","advertid":"56527","length":"length of event","time":1462783357590,"posted":"postedstatus"}]
is not array? when trying splice error events.splice not function.
any aprecciated.
you can't store array/object in sessionstorage.
web storage can store strings.
have string in sessionstorage['events']
key, processed via json.stringify()
method.
deal array further filtering - decode string json.parse()
method like:
var arr = json.parse(sessionstorage['events']); ...
https://developer.mozilla.org/en-us/docs/web/api/web_storage_api/using_the_web_storage_api
Comments
Post a Comment