objectDeepFromEntries.js
function objectDeepFromEntries(entries) {
  if (!isArray(entries)) {
    throw new TypeError(
      `Expected an array of entries. Received ${getTag(entries)}`
    )
  }

  let res = {}
  let isCollection = false

  if (hasNumKey(entries)) {
    res = []
    isCollection = true
  }

  for (const entry of entries) {
    let path = entry[0]
    const value = entry[1]

    if (!isArray(path)) {
      path = [path]
    }

    const root = path.shift()

    if (path.length === 0 && (isCollection && isNaN(root))) {
      res.push({[root]: value})
    } else if (path.length === 0) {
      res[root] = value
    } else if (isCollection && isNaN(root)) {
      res.push({[root]: deepFromEntries(res[root], root, path, value)})
    } else {
      res[root] = deepFromEntries(res[root], root, path, value)
    }
  }

  return res
}
function objectDeepFromEntries(entries) {
  if (!isArray(entries)) {
    throw new TypeError(
      `Expected an array of entries. Received ${getTag(entries)}`
    )
  }

  let res = {}
  let isCollection = false

  if (hasNumKey(entries)) {
    res = []
    isCollection = true
  }

  for (const entry of entries) {
    let path = entry[0]
    const value = entry[1]

    if (!isArray(path)) {
      path = [path]
    }

    const root = path.shift()

    if (path.length === 0 && (isCollection && isNaN(root))) {
      res.push({[root]: value})
    } else if (path.length === 0) {
      res[root] = value
    } else if (isCollection && isNaN(root)) {
      res.push({[root]: deepFromEntries(res[root], root, path, value)})
    } else {
      res[root] = deepFromEntries(res[root], root, path, value)
    }
  }

  return res
}
function objectDeepFromEntries ( entries ) { if ( ! isArray ( entries ) ) { throw new TypeError ( ` ${ getTag ( entries ) } ` ) } let res = { } let isCollection = false if ( hasNumKey ( entries ) ) { res = [ ] isCollection = true } for ( const entry of entries ) { let path = entry [ 0 ] const value = entry [ 1 ] if ( ! isArray ( path ) ) { path = [ path ] } const root = path . shift ( ) if ( path . length === 0 && ( isCollection && isNaN ( root ) ) ) { res . push ( { [ root ] : value } ) } else if ( path . length === 0 ) { res [ root ] = value } else if ( isCollection && isNaN ( root ) ) { res . push ( { [ root ] : deepFromEntries ( res [ root ] , root , path , value ) } ) } else { res [ root ] = deepFromEntries ( res [ root ] , root , path , value ) } } return res }
Create an object from given entries

@param {array} entries

@return {object}

@api public

@example

const entries = [
[
["name"], "John Doe"
],
[
["age"], 25
],
[
["gender"], "Male"
]
]

objectDeepFromEntries(entries)
// -> {name: "John Doe", age: 25, gender: "Male"}
Create an object from given entries