Thursday, 15 July 2010

javascript - flagging duplicates in an array -


After requesting some user images, I end up with an array like this:

 

I need to highlight items that have several times in the label array (here:" picture ").

Ideally, there will be a flag (A) for the item whose label is label again later in the array, and for the last event Second flag (B) (i.e. portraits of both John and Jim have been flagged while Jane Becomes B).

Any help would be greatly appreciated!

I'm not sure what you are trying to do, but it may be that you Need to collect? Owner: "Jim"}, {Name: "Picture", [name: "Picture", Owner: "John"}, {Name: "Home", Owner: "Jim"} : "Gym"}, {name: "picture", owner: "jane"}, {name: "cat", owner: "jane"}]; Var byName = {}; (Var i = 0, l = data. Length; i & lt; l; ++ i) {ifName [data] .name]) {name [data] .name] = []; } Door [Data [i] .name]. Push (data [i] .owner); } // byName == {Picture: ["John", "Jim", "Jane"], Home: ["Jim"], Cat: [By "Jane"]} By Owner = {}; (Var i = 0, l = data. Length; i & lt; l; ++ i) {if by [[data [i]. Manager]] {by [data [i]. Manager] = [];] Onner [Data [i] .owner]. Push (Data [.]);}


Or maybe you prefer it better: Owner: "Jim"}, {Name: "Picture", Owner: "Photo", [Owner: "John"}, {Name: "Home", Owner: "Jim"}, For Var byName = []; (var i = 0, l = "0"), "Jim"}, {name: "picture", owner: "jane"}, {name: "cat", owner: "jane"}] Data; length; i & lt; l; ++ i) for {var done = false; var j = 0; k = data; length; j & lt; k; ++ j) {if (by Name [j] & amp; Name [j] .name == Data [i] .name) {byName [ja] .data.push (data [i] .owner); did = true;}} If ( Done: {data: [data: [data: [i] .owner]})}} / * ByName == [{name: "picture", data: [" [Name: "cat", data: ["jane"]}] * /

Because posting random codes is fun and you know it!


No comments:

Post a Comment