javascript - Pushing hashes into array. Want to update count on same name atttr. hashes -


so, pushing hashes array. hashes same - contain same values. in cases, want not push hash in, update original hash count of +1.

for example.

var hashes = {}; var newhashes = {};  // in case, 'h' key can exists later on again hashes[h] = {    val1: 'val1',    val2: 'val2' }  jquery.extend(true, newhashescontainer, h) somearray.push(h) 

ok. time later, have same content , pushing push_array function

if (newhashcontainer[h]) hashes[h].count++ 

// know exists want add attribute of count it, , increment every time same key hash comes in. can't seem wrap brain around this.

you have create property if doesn't exist , can increment it's value.

so, if you've checked hashes[h] has value want , want increment count on object, can create , increment count this:

if (newhashcontainer[h]) {     // assumes prior code has make sure     // hashes[h] exists     // here, make sure .count property exists     // , increment     if (!hashes[h].count) {         hashes[h].count = 0;     }     hashes[h].count++ } 

your question doesn't make clear newhashcontainer[h] does, i'm assuming makes sure new hash in hashes object. if that's not does, please explain further need or function does.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -