JS Snippets: Array: Difference between revisions
From WikiMLT
m Text replacement - "mlw-continue" to "code-continue" |
m Стадий: 4 [Фаза:Авторизиране, Статус:Разработен]; Категория:JavaScript |
||
Line 35: | Line 35: | ||
{{devStage | {{devStage | ||
| Прндл = JavaScript | | Прндл = JavaScript | ||
| Стадий = | | Стадий = 4 | ||
| Фаза = | | Фаза = Авторизиране | ||
| Статус = | | Статус = Разработен | ||
| ИдтПт = Spas | | ИдтПт = Spas | ||
| РзбПт = {{REVISIONUSER}} | | РзбПт = Spas | ||
| АвтПт = {{REVISIONUSER}} | |||
| ИдтДт = 16.07.2022 | | ИдтДт = 16.07.2022 | ||
| РзбДт = {{Today}} | | РзбДт = 26.09.2022 | ||
| АвтДт = {{Today}} | |||
| ИдтРв = [[Special:Permalink/28303|28303]] | | ИдтРв = [[Special:Permalink/28303|28303]] | ||
| РзбРв = {{REVISIONID}} | | РзбРв = [[Special:Permalink/31923|31923]] | ||
| АвтРв = {{REVISIONID}} | |||
}} | }} | ||
</div> | </div> | ||
</noinclude> | </noinclude> |
Revision as of 11:50, 18 February 2023
Intersect two Arrays
const arr1 = [1, 2, 3, 4];
const arr2 = [1, 2, 5, 6];
const intersection = arr1.filter(value => arr2.includes(value));
console.log(intersection);
(2) [1, 2]
Reference: How to find the intersection of arrays in JavaScript by Reactgo
Get an Array elements by an Array of indexes
const arr1 = ['a', 'b', 'c', 'd', 'e', 'f'];
const arr2 = [1, 3, 4, 0];
const intersection = arr1.filter((value, index) => arr2.includes(index)); // arr2.includes(index) ? true : false
console.log(intersection);
(3) ['a', 'b', 'd', 'e']