下划线连接字符串变驼峰连接

var arr = [
  'so_no_item',
  'soid',
  'original_part_no',
  'quantity',
  'uom',
  'status',
  'delivery_block',
  'part_description',
  'internal_status',
  'default_warehouse',
  'default_location',
]
arr = arr.map(value => {
  let str = value.split('_')
  let newValue = str[0]
  str.forEach((item,index) => {
    str[index] = str[index].substring(0,1).toUpperCase() +  str[index].substring(1)
    if (index>0) {
      newValue += str[index].substring(0,1).toUpperCase() + str[index].substring(1)
    }
  })
  return {
    name: str.join(' '), 
    width: 160, 
    isShow: true,
    value: newValue
  }
})
console.log(JSON.stringify(arr))


[{"name":"So No Item","width":160,"isShow":true,"value":"soNoItem"},{"name":"Soid","width":160,"isShow":true,"value":"soid"},{"name":"Original Part No","width":160,"isShow":true,"value":"originalPartNo"},{"name":"Quantity","width":160,"isShow":true,"value":"quantity"},{"name":"Uom","width":160,"isShow":true,"value":"uom"},{"name":"Status","width":160,"isShow":true,"value":"status"},{"name":"Delivery Block","width":160,"isShow":true,"value":"deliveryBlock"},{"name":"Part Description","width":160,"isShow":true,"value":"partDescription"},{"name":"Internal Status","width":160,"isShow":true,"value":"internalStatus"},{"name":"Default Warehouse","width":160,"isShow":true,"value":"defaultWarehouse"},{"name":"Default Location","width":160,"isShow":true,"value":"defaultLocation"}]

 

转载于:https://www.cnblogs.com/guozongzhang/p/10942810.html

你可能感兴趣的:(下划线连接字符串变驼峰连接)