fibonacci sequence in javascript using for loop

Solutions on MaxInterview for fibonacci sequence in javascript using for loop by the best coders in the world

showing results for - "fibonacci sequence in javascript using for loop"
Christian
01 Jan 2020
1let fibonacci = [0, 1]; // set initial conditions
2
3for (let i = 2; i < 10; ++i) {
4    // add the two previous elements to get the current element
5    fibonacci[i] = fibonacci[i - 2] + fibonacci[i - 1];
6}
7
8console.log(fibonacci); // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]