-1

How to check the array list has contains value?? for example:

var number = [1, 9, 9, 4];

if(number == [1, 9, 9, 4]){ //true}
else if(number == [2, 1, 5, 4){ //false;}
else if(number == [9, 1, 4, 9){ //false;}

if there any method to see to check the array list has contains value eg"1994"?? Thank you very much!!!!

tommy
  • 99
  • 1
  • 2
  • 9
  • 1
    The posted question does not appear to include [any attempt](https://idownvotedbecau.se/noattempt/) at all to solve the problem. StackOverflow expects you to [try to solve your own problem first](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users), as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a [MCVE]. For more information, please see [ask] and take the [tour]. – CertainPerformance Nov 23 '18 at 07:33
  • Note that objects are never `==` or `===` to each other unless they reference the same thing in memory – CertainPerformance Nov 23 '18 at 07:33
  • Simple enough, use indexOf method on array, number.indexOf(subject), if not -1 then its present. – SPlatten Nov 23 '18 at 07:33
  • You can compare arrays as string using JSON.stringify – mplungjan Nov 23 '18 at 07:34

1 Answers1

0

You can go like this:

 function arrays_equal(a,b) { return !!a && !!b && !(a<b || b<a); }

 var number1 = [1, 9, 9, 4];
 var number2 = [1, 9, 9, 4];
 var number3 = [1, 3, 2, 4];
 var number4 = [2, 3, 2, 4];

console.log(arrays_equal(number1, number2));
console.log(arrays_equal(number1, number3));
console.log(arrays_equal(number2, number3));
lifeisbeautiful
  • 817
  • 1
  • 8
  • 18