Hi,
I am using array method but i have some doubt… when did i use call back function and return keyword… can you please tell me… another doubt i am using array and i have to push some value in array… then why can’t stored in variable in push method i have attached snapshot please see…
If I understand your first question correctly, you want to know when to use return in an arrow callback function.
The answer is that if you wrap your function body in curly braces then you have to write “return”, otherwise not.
const callback = (v) => v === "John";
const another = (v) => {
return v === "John";
}
I think your second question is about the value returned by the array’s push function. This function modified the array by inserting the element and returns its new length. You can see the docs here.
when I use callback function in array methods?
You can use arrow functions with Array.sort, Array.find, etc.
Yes, but i don’t know how to find use arrow function in paricular methods… is there any hints
It’s simple. Callback using a traditional function:
const numbers = [1, 2, 3, 4, 5];
const findNumber = numbers.find(function (number) {
return number > 3;
});
Callback using an arrow function:
const numbers = [1, 2, 3, 4, 5];
const findNumber = numbers.find((number) => number > 3);
i think totally 32 array methods… can you please tell me which array method using only call back function…
Are you asking which array functions only accept the traditional function syntax? Is this your question?