Click here to Skip to main content
15,891,937 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am building a web site and use jquery to call the webservice. but my webservice resturns duplicate values in a array.

how can i remove those values and only unique values in jquery ajax call?
Posted

1 solution

Any effort? This has been done so many times before and internet is full of such examples.

However, my first question would be if you are in control of the web service? If yes, I would rather remove the duplicate values on the web service method itself. It will give you an advantage that you will have similar behaviour across all consumers of your web service.

Otherwise, you could use the link below to start with:

http://manasbhardwaj.net/get-unique-values-from-a-javascript-array-using-jquery/

Disclaimer: Points to my own article.

JavaScript
function GetUnique(inputArray)
{
	var outputArray = [];
	for (var i = 0; i < inputArray.length; i++)
	{
		if ((jQuery.inArray(inputArray[i], outputArray)) == -1)
		{
			outputArray.push(inputArray[i]);
		}
	}
	return outputArray;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900