current position:Home>Vue difference between two arrays

Vue difference between two arrays

2022-04-29 05:21:08Haocheng

vue The difference between the two arrays

What is the situation now , For example, ha , I have an array A, How many numbers are there , Then I have an array B, There are a few more numbers in it , Then I want to know the array A Which numbers are in the array B There is no the , Or arrays B Which numbers are in the array A There is no the , Do you understand ? That's what it means .

You can write your own logic , It's just hard work , Of course it can , But what? , I compare lazy , Don't want to make wheels again , therefore , Now you need to use a plug-in —— Lodash .


Lodash Chinese document


First of all, install it .

npm i --save lodash

And then use , First of all, we will introduce a new idea on the page .

import lodash from "lodash";

Then it can be used .

// [3.1, 2.2, 1.3]  in  [4.4, 2.5]  No value to print 
let a = lodash .differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor);
console.log('=> ', a)
// => [3.1, 1.3]

If there are objects in the array , The third parameter is the field name to be compared in the object .

In fact, the Chinese document link given above is more detailed , There are many processing functions , You can use it according to your own needs .

complete !

copyright notice
author[Haocheng],Please bring the original link to reprint, thank you.

Random recommended