1// declare the array starting with the first 2 values of the fibonacci sequence
2 let fibonacci = [0,1];
3
4 function listFibonacci(num) {
5 // starting at array index 1, and push current index + previous index to the array
6 for (let i = 1; i < num; i++) {
7 fibonacci.push(fibonacci[i] + fibonacci[i - 1]);
8 }
9 console.log(fibonacci);
10 }
11
12 listFibonacci(10);
13
1// number fibonnaci to array format
2function fibonacci(nums) {
3
4 let fib = [0, 1];
5 let data = [];
6
7 for(let i = 2; i <= nums; i++) {
8 fib[i] = fib[i - 1] + fib[i - 2];
9 data.push(fib[i]);
10 }
11
12 return data;
13}
1var i;
2 var fib = []; // Initialize array!
3
4 fib[0] = 0;
5 fib[1] = 1;
6 for (i = 2; i <= 10; i++) {
7 // Next fibonacci number = previous + one before previous
8 // Translated to JavaScript:
9 fib[i] = fib[i - 2] + fib[i - 1];
10 console.log(fib[i]);
11 }