Hello - I've read a ton of stuff about deleting duplicate values in an array. They are all very useful - they just haven't addressed an array of objects.
Here's my array:
[HTML]
var sDat = [{
sid:12,
scode:"code",
sname:"Sam"
},
{
sid:12,
scode:"code",
sname:"Sam"
},
{
sid:139,
scode:"code",
sname:"Jake"
}];
[/HTML]
The array is produced from JSON sent to me from a database query. I can't do a "group by" in the sql query - i actually need the repeats in a different array.
Anyway - I want to be able to remove duplicate sDat.sid entries in my sDat array - but I'm having difficulties discovering a way to handle it.
Any ideas?
1 16569 gits 5,390
Expert Mod 4TB
hi ...
for such tasks we may use something like the following example: - var sDat = [
-
{ sid:12, scode:"code", sname:"Sam" },
-
{ sid:12, scode:"code", sname:"Sam" },
-
{ sid:139, scode:"code", sname:"Jake"}
-
];
-
-
function cleanup(arr, prop) {
-
var new_arr = [];
-
var lookup = {};
-
-
for (var i in arr) {
-
lookup[arr[i][prop]] = arr[i];
-
}
-
-
for (i in lookup) {
-
new_arr.push(lookup[i]);
-
}
-
-
return new_arr;
-
}
-
-
var n = cleanup(sDat, 'sid');
-
that makes use of javascript objects and the for-in loop construct ...
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics
by: NiQ |
last post by:
Hello every one,
this is about an array of string and may be have done several time
before but i need it and wasnt able to find it so here is the problem
i have an array of strings with contains...
|
by: Patrick G. |
last post by:
Greetings all:
ASP VB, SQL Svr 2000
I am pulling data from 3 tables.
table1 holds item details
table2 holds publication types and the item id from table1
table3 holds category types and...
|
by: Sam Collett |
last post by:
How do I remove an item with a specified value from an array?
i.e. array values 1,2,2,5,7,12,15,21
remove 2 from array would return
1,5,7,12,15,21
(12 and 21 are NOT removed, duplicates are...
|
by: Voetleuce en fênsievry |
last post by:
Hello everyone.
I'm not a JavaScript author myself, but I'm looking for a method to
remove duplicate words from a piece of text. This text would
presumably be pasted into a text box.
I have,...
|
by: dale.zjc |
last post by:
I've got the following table data:
11652 5.99
11652 0.14
12996 5.03
12996 0.12
12996 7.00
And I need to write a query to return only rows 2 and 4, since the
remaining rows have duplicate...
|
by: brasilino |
last post by:
Hi Folks:
I've been looking (aka googling) around with no success.
I need a usability beyond 'pop()' method when removing an Array
elements. For example:
oName = new...
|
by: whatnameisnottaken |
last post by:
right now i have gotten all the classes to print out using helpdbg. Now i want to remove the duplicate class names out of an array so i can just print one of each.
This is the output i have.
...
|
by: chandru8 |
last post by:
hi to all
iam using vb6.0 can any one tell me how to duplicate values in a array if possible i want to delete the duplicate values
its urgent
thanks
|
by: dawn123 |
last post by:
I have a 2-d array that the user enters tress species and diameter so it looks something like:
sm 10
rm 18
bf 12
sm10
sm10
rm18
and so on.. I need to be able to seach though my array and find...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |