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

Popular posts from this blog

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -