Menu
Underscore.js LogoUnderscore.js Logo
英文官网GitHub
🌜
🌞
Underscore.js LogoUnderscore.js Logo
  • 英文官网
  • GitHub
  • Underscore.js 简介
  • 集合(Collections)
    • each
    • map
    • reduce
    • reduceRight
    • find
    • filter
    • where
    • findWhere
    • reject
    • every
    • some
    • contains
    • invoke
    • pluck
    • max
    • min
    • sortBy
    • groupBy
    • indexBy
    • countBy
    • shuffle
    • sample
    • toArray
    • size
    • partition
  • 数组(Arrays)
    • first
    • initial
    • last
    • rest
    • compact
    • flatten
    • without
    • union
    • intersection
    • difference
    • uniq
    • zip
    • unzip
    • object
    • chunk
    • indexOf
    • lastIndexOf
    • sortedIndex
    • findIndex
    • findLastIndex
    • range
  • 函数(Functions)
    • bind
    • bindAll
    • partial
    • memoize
    • delay
    • defer
    • throttle
    • debounce
    • once
    • after
    • before
    • wrap
    • negate
    • compose
    • restArguments
  • 对象(Objects)
    • keys
    • allKeys
    • values
    • mapObject
    • pairs
    • invert
    • create
    • functions
    • findKey
    • extend
    • extendOwn
    • pick
    • omit
    • defaults
    • clone
    • tap
    • has
    • property
    • propertyOf
    • matcher
    • isEqual
    • isMatch
    • isEmpty
    • isElement
    • isArray
    • isObject
    • isArguments
    • isFunction
    • isString
    • isNumber
    • isFinite
    • isBoolean
    • isDate
    • isRegExp
    • isError
    • isSymbol
    • isMap
    • isWeakMap
    • isSet
    • isWeakSet
    • isNaN
    • isNull
    • isUndefined
  • 工具函数(Utility)
    • noConflict
    • identity
    • constant
    • noop
    • times
    • random
    • mixin
    • iteratee
    • uniqueId
    • escape
    • unescape
    • result
    • now
    • template
  • Object-Oriented Style
  • 链式语法(Chaining)
    • chain
    • value
  • 更多链接 & 推荐阅读
  • 更新日志(Change Log)

sample

_.sample(list, [n])
从 list 中产生一个随机样本。传递一个数字表示从 list 中返回 n 个随机元素。否则将返回一个单一的随机项。

_.sample([1, 2, 3, 4, 5, 6]);
=> 4
_.sample([1, 2, 3, 4, 5, 6], 3);
=> [1, 6, 2]
Previous
« shuffle
Next
toArray »

同类工具

  • Lodash

社区

  • GitHub

友链

  • Bootstrap中文网
  • React
  • Next.js
  • Docusaurus
  • NPM
  • Yarn
  • Gatsby
  • Webpack
  • Rollup
  • Parcel
  • PurgeCSS
  • MDX
  • Markdown
  • TailwindCSS
  • Fastify
  • Preact
  • WebAssembly
  • Deno
京ICP备15031610号-35