0

I am trying to sort out an array and returning the duplicate values. So i know if the value in this case a date exists one or more times. I have been searching and I do only find how to delete the values.

I would like to just return the value that exists one or more times in the array.

This far I have come so long:

var singelbokningar = [];
   $.each(bokadeDatumDone, function(i, el){
   if($.inArray(el, singelbokningar) > -1) singelbokningar.push(el);
});

But it returns a new array without the duplicates.

How should I do?

1 Answer 1

1

Just create another array to hold you duplicates:

var singelbokningar = [];
var duplicates = [];

$.each(bokadeDatumDone, function(i, el) {
   if ( $.inArray(el, singelbokningar) > -1 ) singelbokningar.push(el);
   else duplicates.push(el);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Yes! Thank you! There is only one problem with our code and that is: It should be: ===1 Not > 1 But That is my fault! But thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.