教程 radash tutorial

mapValues

映射对象的值

基本用法

给定一个对象和一个 toValue 回调函数,返回一个新对象,其中所有值都通过 toValue 函数进行映射。回调函数会接收每个条目的值和键。

ts
import { mapValues } from 'radash'

const ra = {
  mode: 'god',
  power: 'sun'
}

mapValues(ra, value => value.toUpperCase()) // => { mode: 'GOD', power: 'SUN' }
mapValues(ra, (value, key) => key) // => { mode: 'mode', power: 'power' }