`_.zip` function on array using JavaScript Library underscore.js ( #shorts )

1 year ago
1

Hi Friends,

`_.zip` function on array using JavaScript Library underscore.js

`_.zip` is a utility function in Underscore.js library that allows you to combine multiple arrays into a single array of list. Each list contains one element from each of the input arrays, aligned by their positions.

In below example, we have three arrays: `names`, `ages`, and `heights`. We use `_.zip` to combine them into a single array `people` of list, where each list contains one element from each of the input arrays. The resulting `people` array contains lists for each person, with their name, age, and height in inches.

// syntax
_.zip(*arrays)

// example
var names = ["Angel", "Bob", "Charry"];
var ages = [30, 25, 35];
var heights = [68, 72, 70];

var people = _.zip(names, ages, heights);

console.log(people);
// [
// ["Angel", 30, 68],
// ["Bob", 25, 72],
// ["Charry", 35, 70]
// ]

#javascript #under #score #underscore #underscorejs #zip #underscorezip #zipfunction #unique #object #array #string #nodejs #javascriptinterview #method #js #jquery #function #shorts #viral #popular #latest #new #coders #development #code #dev #interview #php #trend #trending #answer #laravel #youtube #instagram #socialmedia #education #edit #how #india #knowledge #quiz #reels #short #subscribe #share #update #video #web #webdeveloper #website #webdesign #ytshorts #youtuber #princecheema_official @princecheema_official

Loading comments...