JavaScriptのオブジェクトとは何ですか?任意のプロパティにアクセスしますか?**
オブジェクトのプロパティへのアクセス
オブジェクトがなければ、JavaScriptはありません。ブール値、数値、関数などはすべてオブジェクトです。オブジェクトのプロパティへのアクセスについては、次のメソッドで説明します。
例-1
<html>
<body>
<script>
myObj = {"name":"Ramesh","age":30,"family":
[{"mother":"Geetha","father":"Rao"}],"city":"Berlin"};
var res = myObj.family[0].mother;
document.write(res);
</script>
</body>
</html> 出力
Geetha
例-2
<html>
<body>
<script>
myObj = {"name":"Ramesh","age":30,"family":
[{"mother":"Geetha","father":"Rao"}],"city":"Berlin"};
var res = myObj.city;
document.write(res);
</script>
</body>
</html> 出力
Berlin
-
JavaScriptでオブジェクトを作成してそのプロパティにアクセスするにはどうすればよいですか?
以下は、オブジェクトを作成し、JavaScriptでそのプロパティにアクセスするコードです- 例 <!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <st
-
JavaScriptのidプロパティで複雑なオブジェクトを検索する
このような複雑なJSONオブジェクトがあるとします- const obj = { "id": "0001", "fieldName": "sample1", "fieldValue" "0001", "subList": [ { "id