Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> JavaScript

JavaScript में नेस्टेड ऑब्जेक्ट कीज़ की वैल्यू कैसे बदलें?

उदाहरण

डॉट नोटेशन और स्क्वायर ब्रैकेट्स से नेस्टेड ऑब्जेक्ट प्रॉपर्टीज़ अपडेट करें।

var details = { 
    "customer": { 
        "customerDetails": { 
            "otherDetails": [ 
                { "customerDetails": { "isMarried": false } }, 
                { "customerDetails": { "isMarried": false } }, 
                { "customerDetails": { "isMarried": false } } 
            ] 
        } 
    } 
}; 
console.log("All values are set to true="); 
for (var index = 0; index < details.customer.customerDetails['otherDetails'].length; index++) { 
    details.customer.customerDetails['otherDetails'][index].customerDetails['isMarried'] = true; 
} 
for (var index = 0; index < details.customer.customerDetails['otherDetails'].length; index++) { 
    console.log("isMarried:" + details.customer.customerDetails['otherDetails'][index].customerDetails['isMarried']); 
}

प्रोग्राम चलाने के लिए:

node fileName.js

आउटपुट

PS C:\Users\Amit\javascript-code> node demo186.js 
All values are set to true= 
isMarried:true 
isMarried:true 
isMarried:true
  1. जावास्क्रिप्ट का उपयोग करके ऐरे में नेस्टेड ऑब्जेक्ट वैल्यूज का योग जावास्क्रिप्ट का उपयोग करके ऐरे में नेस्टेड ऑब्जेक्ट वैल्यूज का योग

    जावास्क्रिप्ट का उपयोग करके ऐरे में नेस्टेड ऑब्जेक्ट वैल्यूज का योग करने का कोड निम्नलिखित है - उदाहरण <!DOCTYPE html> <html lang=en> <head> <meta charset=UTF-8 /> <meta name=viewport content=width=device-width, initial-scale=1.0 /> <title>Document</title>

  1. जावास्क्रिप्ट में Object.keys().map() बनाम Array.map() जावास्क्रिप्ट में Object.keys().map() बनाम Array.map()

    जावास्क्रिप्ट में Object.keys().map() और Array.map() दिखाने का कोड निम्नलिखित है - उदाहरण <!DOCTYPE html> <html lang=en> <head> <meta charset=UTF-8 /> <meta name=viewport content=width=device-width, initial-scale=1.0 /> <title>Document</title> <style>

  1. - MongoDB नेस्टेड ऑब्जेक्ट में मान कैसे बढ़ाएं (increment)?

    $inc और पोजिशनल ऑपरेटर $ से नेस्टेड ऐरे ऑब्जेक्ट अपडेट करें MongoDB में ऐरे के अंदर नेस्टेड ऑब्जेक्ट के फील्ड को बढ़ाने (increment) के लिए $inc के साथ पोजिशनल $ ऑपरेटर का उपयोग करें। उदाहरण डेटा > db.incrementValueDemo.insertOne({ StudentName: Larry, StudentCountryName: US, StudentDetails