From 3b2a44df5119dc483bf52af989bc90d8c3c58d7f Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Thu, 16 Sep 2021 23:42:30 +0900 Subject: orphaned/Map を削除 (#2339) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 古い文章であるため、現在の JavaScript の Map へのリダイレクトに変更 --- files/ja/orphaned/map/index.html | 230 --------------------------------------- 1 file changed, 230 deletions(-) delete mode 100644 files/ja/orphaned/map/index.html (limited to 'files/ja/orphaned') diff --git a/files/ja/orphaned/map/index.html b/files/ja/orphaned/map/index.html deleted file mode 100644 index 970083dc95..0000000000 --- a/files/ja/orphaned/map/index.html +++ /dev/null @@ -1,230 +0,0 @@ ---- -title: Map -slug: orphaned/Map -original_slug: Map ---- -

{{ SeeCompatTable() }}

- -

{{ warning("The SpiderMonkey Map implementation is a prototype and the Map API and semantics specifications are unstable. The SpiderMonkey implementation may not reflect the latest specification draft. It is subject to change anytime. It is provided as an experimental feature. Do not rely on it for production code.") }}

- -

Introduction

- -

Map オブジェクトはシンプルなキーバリューマップです。 キーとバリューにあらゆる値(オブジェクトとプリミティブ値)が使用できます。

- -

Key equality is based on the "same-value" algorithm: NaN is considered the same as NaN (even though NaN !== NaN), -0 and +0 are considered distinct (even though -0 === +0), and all other values are considered equal according to the semantics of the === operator.

- -

API

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ConstructorDescription
new Map([iterable])Returns a new Map object.  If iterable is an Array or other iterable object whose elements are key-value pairs (2-element Arrays), then each of those key-value pairs will be added to the new Map.
MethodDescription
myMap.get(key)Returns the value associated to the key, or undefined if there is none.
myMap.set(key, value)Sets the value for the key in myMap. Returns undefined.
myMap.has(key)Returns a boolean asserting whether a value has been associated to the key in myMap or not
myMap.delete(key)Removes any value associated to the key. After such a call, myMap.has(key) will return false.
myMap.clear()Removes all key/value pairs from myMap.
PropertyDescription
myMap.size -

Returns the number of key/value pairs in myMap.

- In Firefox 18 and earlier, size was a method. In Firefox 19 and later it is a property.
- -

A Map object can iterate its elements in insertion order - a for..of loop will return an array of [key, value] for each iteration.

- -

Examples

- -
var myMap = new Map();
-
-var keyObj = {},
-    keyFunc = function () {},
-    keyString = "a string";
-
-// setting the values
-myMap.set(keyString, "value associated with 'a string'");
-myMap.set(keyObj, "value associated with keyObj");
-myMap.set(keyFunc, "value associated with keyFunc");
-
-myMap.size; // 3
-
-// getting the values
-myMap.get(keyString);    // "value associated with 'a string'"
-myMap.get(keyObj);       // "value associated with keyObj"
-myMap.get(keyFunc);      // "value associated with keyFunc"
-
-myMap.get("a string");   // "value associated with 'a string'"
-                         // because keyString === 'a string'
-myMap.get({});           // undefined, because keyObj !== {}
-myMap.get(function() {}) // undefined, because keyFunc !== function () {}
-
- -

NaN can also be used as a key. Even though every NaN is not equal to itself (NaN !== NaN is true), the following example works, because NaNs are indistinguishable from each other:

- -
var myMap = new Map();
-myMap.set(NaN, "not a number");
-
-myMap.get(NaN); // "not a number"
-
-var otherNaN = Number("foo");
-myMap.get(otherNaN); // "not a number"
-
- -

Also note that JavaScript has two zero values, +0 and -0. These two zero values are treated as different keys in Maps:

- -
var myMap = new Map();
-myMap.set(0, "positive zero");
-myMap.set(-0, "negative zero");
-
-0 === -0; // true
-
-myMap.get(-0); // "negative zero"
-myMap.get(0);  // "positive zero"
-
- -

Maps can be iterated using a for..of loop:

- -
var myMap = new Map();
-myMap.set(0, "zero");
-myMap.set(1, "one");
-for (var [key, value] of myMap) {
-  alert(key + " = " + value);
-}
-// Will show 2 alerts; first with "0 = zero" and second with "1 = one"
-
- -

Objects and maps compared

- -

Objects are similar to Maps in that both let you set keys to values, retrieve those values, delete keys, and detect whether something is stored at a key. Because of this, Objects have been used as Maps historically; however, there are important differences between Objects and Maps that make using a Map better.

- - - -

Use maps over objects when keys are unknown until run time, and when all keys are the same type and all values are the same type.

- -

Use objects when there is logic that operates on individual elements.

- -

Browser compatibility

- -

{{ CompatibilityTable() }}

- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support31 [1]{{ CompatGeckoDesktop("13") }}{{ CompatNo() }}{{ CompatNo() }}{{ CompatNo() }}
iterable{{ CompatNo() }}{{ CompatGeckoDesktop("17") }}{{ CompatNo() }}{{ CompatNo() }}{{ CompatNo() }}
Map.clear()31 [1]{{CompatGeckoDesktop("19")}}{{ CompatNo() }}{{ CompatNo() }}{{ CompatNo() }}
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{ CompatNo() }}{{ CompatGeckoMobile("13") }}{{ CompatNo() }}{{ CompatNo() }}{{ CompatNo() }}
iterable{{ CompatNo() }}{{ CompatGeckoDesktop("17") }}{{ CompatNo() }}{{ CompatNo() }}{{ CompatNo() }}
Map.clear(){{ CompatNo() }}{{CompatGeckoMobile("19")}}{{ CompatNo() }}{{ CompatNo() }}{{ CompatNo() }}
-
- -

[1] The feature is available behind a preference. In chrome://flags, activate the entry “Enable Experimental JavaScript”.

- -

See also

- - -- cgit v1.2.3-54-g00ecf