Understanding data structures and performing operations
let text = 'Hello World';
text.slice(0, 5); // 'Hello'
text.toUpperCase(); // 'HELLO WORLD'
text.toLowerCase(); // 'hello world'
text.split(' '); // ['Hello', 'World']
let arr = [10, 20, 30, 40, 50]; arr.push(60); // Add to end arr.pop(); // Remove from end arr.unshift(5); // Add to start arr.shift(); // Remove from start arr.slice(1, 4); // Extract part
let person = { name: 'John', age: 25 };
person.email = 'john@example.com'; // Add
person.age = 26; // Update
delete person.city; // Delete
let students = [
{ name: 'John', age: 20, grade: 'A' },
{ name: 'Sarah', age: 22, grade: 'B' }
];
console.log(students[0].name); // 'John'
let person = {
name: 'John',
address: {
city: 'New York',
zip: '10001'
}
};
console.log(person.address.city); // 'New York'
Array: [5, 12, 8, 20, 3]
let numbers = [5, 12, 8, 20, 3];
let value = numbers[1]; // 12
if (value > 10) {
console.log('Greater than 10');
}
Students: John (0), Sarah (1), Mike (2)
let students = [
{ name: 'John', age: 20 },
{ name: 'Sarah', age: 22 }
];
console.log(students[1].name); // 'Sarah'
let arr1 = [1, 2, 3]; let arr2 = [4, 5, 6]; let merged = []; // Add all items from both arrays
let text = 'Hello World JavaScript';
let words = text.split(' ');
console.log(words[0]); // 'Hello'
console.log(words[1]); // 'World'
let item = {
name: 'Apple',
price: 50,
quantity: 3
};
let total = item.price * item.quantity; // 150