• Register
1 vote
51 views

Problem:

Hello good souls,

var myarr1 = [1, 2, 3, 4, 5];
var myarr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

I have two simple arrays like above. I want to sort out the common values between those two arrays. So can you find common elements in two arrays javascript for me? Please keep the program as simple as possible that I can understand easily.

Thanks for your effort and valuable time buddy.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

You can use a function called $.grep() to find out the common values between two arrays.

var myarr1 = [1, 2, 3, 4, 5];
var myarr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var common = $.grep(myarr1, function(element) {
    return $.inArray(element, myarr2 ) !== -1;
});
console.log(common);

This program might help you. Keep posting, Man

13 9 6
94,240 points

Related questions

0 votes
1 answer 33 views
33 views
I have to work with comparision between objects of two arrays this is actually my University Assignment someone please help me
asked Nov 10, 2020 Han Li 710 points
0 votes
1 answer 19 views
19 views
I want to know how to get multiple checked checkbox value in Jquery.
asked Oct 5, 2020 Daniel Anderson 4k points
0 votes
1 answer 22 views
22 views
I am new to this. I was doing that but I got into some problems.
asked Nov 3, 2020 TeamScript 13.5k points
0 votes
1 answer 40 views
40 views
Problem : My function accepts the two arrays of integers and returns true if below conditions are met 1. Arrays have the same length and 2. Each m.element should be less than each n.element of the same index All my test cases are passing except when int[] m = {1, 2, 3} and int[] n = ... = (m[j] < n[j]); for (j = 0; j <= m.length - 1; j++) {} return (sameLength && digitDifference); }
asked Dec 3, 2019 alecxe 7.5k points
0 votes
1 answer 17 views
17 views
I am trying to solve a "practice" problem, and I am not able to pass all the tests for it. The problem is: Write a method called equals that takes two arrays of strings and returns true if they are equal; that is, if both sets are the same length and contain ... { result = true; } else { result = false; } } } else { return false; } return result; } Expected performance: falseMy return:true
asked Oct 19, 2020 sasha 8.7k points
0 votes
1 answer 45 views
45 views
Solve this, please. I am new.
asked Nov 20, 2020 TeamScript 13.5k points
0 votes
1 answer 5 views
5 views
Problem: Given the line of code var value = $("#text").val(); and value = 9.61, I need to convert 9.61to 9:61. How can I use the JavaScript function substitute here?
asked Feb 14 sasha 8.7k points
0 votes
1 answer 12 views
0 votes
1 answer 36 views
36 views
Problem: I have very less knowledge on javascript and jquery. I want to know how can I get the full path of any file while selecting that file using <input type=&lsquo;file&rsquo;> <input type="file" id="fileUpload"> <script type="text/javascript"> function getFilePath(){ ... browsers (FF or chrome) only give the name of file. Is there some other way to get the full path of any selected file?
asked Aug 2, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 23 views
23 views
Problem: I am getting the following error, even if I have jquery-ui in my application.js file the file 'jquery-ui' could not be found (in / home / jeff / jobs / projects / to / media / app / assets / javascripts / application .js: 14) application.js //= require jquery //= require jquery_ujs //= require jquery-ui //= require jquery.validate.min Can anybody help me?
asked Nov 4, 2020 sasha 8.7k points