I have array of array, and i want array of object in return how would I do this in JS or using underscore-plugin

underscore js
npm underscore
underscore example
lodash
underscore js cdn
underscore vs lodash
underscore js tutorial
_.uniq = function(array, issorted, iterator)
var arr = [
  [{a: "apple", b: "ball"}, {c: "cat", d: "dog"}],
  [{e: "elephent", f: "flight"}, {g: "god", h: "hen"}]
];

The expected result is --

var exp = [
  {a: "apple", b: "ball"}, 
  {c: "cat", d: "dog"},
  {e: "elephent", f: "flight"}, 
  {g: "god", h: "hen"}
]

You can use flat():

var arr = [[{a: "apple", b: "ball"}, {c: "cat", d: "dog"}],[{e: "elephent", f: "flight"}, {g: "god", h: "hen"}]];
console.log(arr.flat());

Underscore.js, Returns a copy of the object where the keys have become the Creates a new object with the given prototype, optionally Any nested objects or arrays will be copied by reference, not duplicated. Like extend, but only copies own properties over to the Does the object contain the given key? An array-like or iterable object to convert to an array. mapFn Optional Map function to call on every element of the array. thisArg Optional Value to use as this when executing mapFn. Return value. A new Array instance. Description. Array.from() lets you create Arrays from: array-like objects (objects with a length property and indexed elements

Try using this code:

[].concat(...arr)

Underscore.js, The Underscore.js is a JavaScript library that provides a lot of useful functions that helps in the programming in a big way like the map, filter, invoke etc even without using any built-in objects. function returns the value which is either true (when the element is present in Passing an array to the _.contains function(): The . This seems to work fine. However, another case has arisen, one in which I need to pull back the team object based on its location + " " + name. So I tried to do the same thing using underscore.js, passing in the parameter name, and changing the predicate in ._find to return obj.location + " " + obj.name == name.

You can access index 0 of array and assign it to existing variable you store your array

Something like

arr = arr[0]

*Since question was misread, this answer needs update

let newArr = []
newArr = arr.map((item) {
    return item[0]
})

This leaves arr unchanged. If you'd rather modify arr use forEach instead of map

Underscore.js, The Underscore.js is a JavaScript library that provides a lot of useful functions that in a big way like the map, filter, invoke etc even without using any built-in objects. Passing the array with a function which returns the number and it will sort the _sortBy() function takes the element from the list one by one and do the​  There's a very simple way to do this: var newFoo = foo.map(el=>Object.values(el)); This is modern, ES2017 code. Object.values gets the values of an object in an array. The code says "for every element in foo, get the values of the object and return them in an array". You could do this in pre-2017 code with something like this:

Underscore-java, Underscore-java is a port of Underscore.js for Java. Underscore-java is compatible with Java 6 and later. The iterator is bound to the context object (​component or struct), if one is passed. Looks through each value in the collection, returning an array of all the values fromXml() method in string and lodash plugins. The isArray () method determines whether an object is an array. This function returns true if the object is an array, and false if not. Thank You For Helping Us! Your message has been sent to W3Schools. W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding.

Package, Check methods you can use natively without lodash/underscore Make use of native JavaScript object and array utilities before going big. Object. _.assign; _.​extend; _.get; _.keys; _.omit; _.pick; _.pickBy; _.toPairs; _.values Similar to without, but returns the values from array that are not present in the other arrays. Design. This library uses an array-like object to implement all its methods. This is very similar to how jQuery lets you do: $('.modal')[0] and $('p').length. This library differs from component/enumerable in that it has events and does not wrap the array.

Lazy.js - v0.5.1, var result = Lazy(people) .pluck('lastName') .filter(function(name) { return name. Every method from Underscore should have the same name and (almost) identical behavior in Lazy.js, (If you ever do want an array, simply call toArray on the resulting sequence.) So, Lazy.js is basically Underscore with lazy evaluation. When you have an object, you only need the identifier you used as key. Update When using an array the fastest way is to map and change the one you want to change.

Comments
  • [].concat(...arr)
  • @tg24 ... arr is [[],[]]
  • Hey Arup, you're getting downvotes and votes to close because your question doesn't show what you've tried and ask for specific help it is just asking a broad question on how to achieve something. Can you be more specific?
  • probably worth reviewing stackoverflow.com/help/how-to-ask
  • wont work on any microsoft browser though - not even Edge - see documentation for alternatives
  • Generally, answers are much more helpful if they include an explanation of what the code is intended to do, and why that solves the problem without introducing others.
  • Have you tried and compared your solution to the expected results?
  • He edited the question, previous array sample was [ [ {}, {}, {} ] ]
  • Oh right..bad sight..you can try updated answer, it should work fine