Function take

  • Takes n elements from the beginning of the value (Array, Object, Set, Map etc). If n is a function, it stops as soon as it returns false or z.STOP.

    If options.props & value is an _.isObject() other than realObject, it will retrieve (i.e clone) both:

    • the first n keys/idx of the value (eg the Array elements, Set items etc)
    • the first n of props

    Note: No guaranteed order for property bags like Objects, Sets, Maps etc and return the same value type of input value.

    Type Parameters

    Parameters

    • input: Tinput

      any value to take elements from. Usually an Array, Object, Map, Iterator etc. but you can also pass single values, like a number, string etc - see loopSingles option.

    • n: number | ItakeCallback

      the number of elements to take. If a function, it will be called with (item, keyIdx, value, count). If it returns true it will take items, as soon as it returns false or z.STOP it stops taking items.

    • Optionaloptions: Toptions

      you can optionally pass an IloopOptions object to control which keys / idx are visited (own / inherited / enumerable etc) and more.

    Returns GetMapReturn<Tinput, Toptions, null, null>

    z.filter for filtering elements - the filterSingles option also applies here: if take is used with isSingle values, filterSingles must be true or it will throw an error.