I am learning about arrow functions and split assignments in javaScript.
While referring to MDN WebDoc, I came across the following code.

const materials = [
console.log (materials.map (({"length": lengthFooBArX}) =>lengthFooBArX))

About MDN Arrow Function

The site had the following explanation.
>In this case, you can use the split parameter because you only need the length property: string"length"Corresponds to the property I want to get, but obviously not speciallengthFooBArXIs a variable name that can be changed to any valid variable name

Why can I write the above code even if I check the split assignment?
I don't understand at all and I am in trouble.
Could anyone please teach me?

  • Answer # 1

    For example

    let {"length": len} ='abcd';

    If you write, "Right side ('abcd')oflengthPropertieslenIt means "substitute to", so it is a variablelenToFourIs entered.

    Applying this,getLength ()If you define the function as follows,

    function getLength ({"length": len}) {
      return len;

    getLength ('abcd')IsFourReturns.

    If you write this function as an arrow function,({"length": len}) =>lenis not it. thismap ()If you pass it as an argument of

    let lens = materials.map (({"length": len}) =>len);

    materialsThis arrow function is applied to each element oflensTo[8, 6, 7, 9]Is entered.

    How about?