-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobj.js
More file actions
94 lines (68 loc) · 2.29 KB
/
obj.js
File metadata and controls
94 lines (68 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// let obj ={
// name: "Nandini",
// age: 21,
// weight: 62,
// innerHeight: "5feet 6inch",
// greet: function(){
// console.log("hello ji");
// }
// };
// console.log(obj)
// obj.greet();
// console.log(typeof(obj))
// let arr=[1,2,3,4,5]
// console.log(arr);
// // Creating an array of numbers using array literal notation
// const numbers = [1, 2, 3, 4, 5];
// console.log(numbers)
// // Creating an array of strings using array literal notation
// const fruits = ['apple', 'banana', 'orange'];
// console.log(fruits)
// Creating an array of mixed data types using array literal notation
// const mixed = [1, 'apple', true, { name: 'John' }];
// console.log(mixed)
// // Creating an array of numbers using Array constructor
// const numbers = new Array(1, 2, 3, 4, 5);
// // Creating an array of strings using Array constructor
// const fruits = new Array('apple', 'banana', 'orange');
// // Creating an empty array using Array constructor
// const emptyArray = new Array();
// console.log(numbers); // Output: [1, 2, 3, 4, 5]
// console.log(fruits); // Output: ['apple', 'banana', 'orange']
// console.log(emptyArray); // Output: []
// const fruit= ['apple', 'banana', 'orange', 'grape', 'kiwi'];
// // Accessing the first element of the array
// console.log(fruit[0]); // apple
// // Accessing the third element of the array
// console.log(fruit[2]); // orange
// // Accessing the last element of the array
// console.log(fruit[fruit.length - 1]); // kiwi
// // Accessing an element using a variable
// const index = 1;
// console.log(fruit[index]); // banana
// const fruit = ['apple', 'banana', 'orange'];
// fruit.push('kiwi');
// fruit.push('grapes');
// console.log(fruit);
// // Output: [ 'apple', 'banana', 'orange', 'kiwi', 'grapes' ]
// const fruit = ['apple', 'banana', 'orange'];
// fruit.splice(1,2,"chiku");
// console.log(fruit);
let array=[10,20,30,40,61,53,92];
// let ans = array.map((number)=>{
// return number*number;
// })
// console.log(ans)
// let even = array.filter((number)=>{
// if(number%2 ==0){
// return true;
// }
// else{
// return false;
// }
// });
// console.log(even);
let answer = array.reduce((acc,curr)=>{
return acc+curr;
},0);
console.log(answer);