JavaScriptలో Objects

JavaScript objects డేటాను key-value pairs రూపంలో నిల్వ చేస్తాయి. ప్రతి pair ఒక property. Key అనేది ఒక string. Value అనేది number, string లేదా function వంటి ఏదైనా data type కావచ్చు.

మీరు object literal notation ఉపయోగించి objectsను సృష్టించవచ్చు. మీ డేటాను నిల్వ చేయడానికి curly braces ఉపయోగించండి.

ఒక objectను సృష్టించడం:

మీరు propertiesని రెండు విధాలుగా యాక్సెస్ చేయవచ్చు:

  1. Dot notation Object పేరు మరియు property పేరు మధ్య ఒక period (.) ఉపయోగించండి. ఉదాహరణ: person.firstName

  2. Array-like notation Square brackets మరియు quotes ఉపయోగించండి. మీ keyలో spaces ఉన్నట్లయితే ఇది అవసరం. ఉదాహరణ: address['building no']

ముఖ్యమైన నియమాలు:

మీరు ఒక objectలోని డేటాను మార్చవచ్చు:

ఒక property ఉందో లేదో తనిఖీ చేయడానికి, in operator ఉపయోగించండి. Key ఉంటే ఇది true అని, లేకపోతే false అని రిటర్న్ చేస్తుంది.

ఉదాహరణ: 'employeeId' in employee అనేది true అని రిటర్న్ చేస్తుంది.

Source: https://dev.to/pdhanush26/objects-in-javascript-ma6