hi,
can any one help me on below requirement:
i have 2 arrays as arra1 = [11,1A,1V,BD]
arra2 = [11,22,1A,CD]
i want to sort this and take the similar items
hi,
can any one help me on below requirement:
i have 2 arrays as arra1 = [11,1A,1V,BD]
arra2 = [11,22,1A,CD]
i want to sort this and take the similar items
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vishal YelvePosted Oct 20, 2023, 1:45 PM
Hi Murali,
Try this
Sarthak VarshneyPosted Oct 19, 2023, 4:51 AM
Prasad RaveendranPosted Oct 19, 2023, 1:50 AM
To find the similar items between these arrays, you can use JavaScript's
filtermethod along with theincludesmethod. Here's the code to do that:This code will filter the elements of
array1and create a new arraycommonItemsthat contains only the elements that are also present inarray2. In this example,commonItemswill be['11', '1A'], as these are the values that are present in both arrays.If you want the result to be sorted, you can sort the
commonItemsarray like this:Now,
commonItemswill be['11', '1A']in sorted order.