“Parameter istirahat JavaScript” Kode Jawaban

Parameter istirahat JavaScript

/*The rest parameter syntax allows a function to accept an indefinite
number of arguments as an array, */

function getFirstElementOfArray(...args){
  return args[1]
}

getFirstElementOfArray("shirshak","Sabtech","Javascript")// return shirshak
Shirshak kandel

Parameter istirahat JavaScript

/*
That allows a function to accept an indefinite number of arguments as an array
*/
function fun(...input){
    let sum = 0;
    for(let i of input){
        sum+=i;
    }
    return sum;
}
console.log(fun(1,2)); //3
console.log(fun(1,2,3)); //6
console.log(fun(1,2,3,4,5)); //15 
Tiny Coders

operator istirahat JavaScript

function sum(...numbers) {
	return numbers.reduce((accumulator, current) => {
		return accumulator += current;
	});
};
 
sum(1,2) // 3
sum(1,2,3,4,5) // 15
Brainy Butterfly

Operator istirahat JavaScript

function fun1(...theArgs) {
  console.log(theArgs.length);
}

fun1();  // 0
fun1(5); // 1
fun1(5, 6, 7); // 3
cunhaedu

Parameter REST JavaScript

let func = function(...args) {
    console.log(args);
}

func(3); // [3]
func(4, 5, 6); // [4, 5, 6]
SAMER SAEID

Parameter REST JavaScript

function show(a, b, ...args) {
  console.log(a); // one
  console.log(b); // two
  console.log(args); // ["three", "four", "five", "six"]
}

show('one', 'two', 'three', 'four', 'five', 'six')
SAMER SAEID

Jawaban yang mirip dengan “Parameter istirahat JavaScript”

Pertanyaan yang mirip dengan “Parameter istirahat JavaScript”

Lebih banyak jawaban terkait untuk “Parameter istirahat JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya