"="是什么意思?在JavaScript中意味着什么? [英] What does "=>" mean in JavaScript?

查看:54
本文介绍了"="是什么意思?在JavaScript中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码:

function accum(s) {
  return s.split('').map((x,index) => x.toUpperCase()+Array(index+1).join(x.toLowerCase())).join('-');
}

我想知道什么是"=>".该函数采用一个字符串,并为每个元素的索引号添加许多元素到输出中.这是一个示例:

I would like to know what "=>" is. This function takes a string and for the index number of each element it adds that many elements to the output. Here's an example:

accum("abcd") --> "A-Bb-Ccc-Dddd"
accum("RqaEzty") --> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
accum("cwAt") --> "C-Ww-Aaa-Tttt"

推荐答案

这是ES6中引入的一项新功能,称为箭头功能.左部分表示功能的输入,右部分表示该功能的输出.

It's a new feature that introduced in ES6 and is called arrow function. The left part denotes the input of a function and the right part the output of that function.

所以在你的情况下

s.split('')

将输入拆分为空白,并为结果数组的每个元素应用以下功能:

splits the input on empty spaces and for each element of the resulted array you apply the following function:

(x,index) => x.toUpperCase()+Array(index+1).join(x.toLowerCase())

左边是数组( s.split(''))的随机元素 x 及其对应的索引.第二部分对此输入进行转换.

The left part is the random element, x of the array (s.split('')) and it's corresponding index. The second part applies a transformation to this input.

这篇关于"="是什么意思?在JavaScript中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆