Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js get each pair of values from an array of objects

function uniquePairs(arr) {
    return arr.flatMap((item1, index1) =>
        arr.flatMap((item2, index2) =>
            (index1 > index2) ? [[item1, item2]] : []
        )
    );
}
Comment

js get each pair of values from an array

function uniquePairs(arr) {
    return arr.reduce((acc, current, i) =>
        [...acc, ...(arr.slice(i + 1).map(val => [current, val]))], []);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: angular build deploy url 
Javascript :: html anchor tag javascript confirm 
Javascript :: wait for 1 second in loop in javascript 
Javascript :: pass data to slot vue 
Javascript :: express.js get params 
Javascript :: read files in node js 
Javascript :: how to detect if an video is over js html 
Javascript :: add in to array mongoose 
Javascript :: getting te value of select multiple value 
Javascript :: create-react-app npm yarn 
Javascript :: fetch data with axios in reactjs 
Javascript :: validar array vacio javascript 
Javascript :: how to insert with variables from js to mysql 
Javascript :: moment clone 
Javascript :: js get element by innertext 
Javascript :: get selected text 
Javascript :: remove array item with index 
Javascript :: call python function from javascript 
Javascript :: render first index active tabs in reactjs 
Javascript :: javascript find similar strings 
Javascript :: js sort by two numeric fields 
Javascript :: card type through card number 
Javascript :: search a word and separate in javascript 
Javascript :: extended class call method from super in javascript 
Javascript :: Get width of screen on resize event 
Javascript :: using template literals to create html 
Javascript :: reactstrap dropdown 
Javascript :: date.gettime is not a function 
Javascript :: expo font 
Javascript :: js object sort 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =