---
schema_version: "1"
id: 925982a53e66dcd5429ab8880db97a32fddcc752620d536648b3eb188cfa0a12
title: update
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.3/dw-values-functions-update.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.3/dw-values-functions-update
source_site: docs.mulesoft.com
content_type: documentation
content_hash: b09c01a6ba1f31f1f384ffc91f36b74ac8c3da4c6f18fef1a0cd4bc01e44b52c
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
# update

## [](#update1)update(Object, String): Any

この ​`update`​ 関数は、指定された文字列値でオブジェクトの項目を更新します。

この関数は、指定された項目と値を含む新しいオブジェクトを返します。

### [](#パラメーター)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>objectValue</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">更新するオブジェクト。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>fieldName</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">項目の名前を提供する文字列。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、指定された値でオブジェクト ​`{name: "Mariano"}`​ の ​`name`​ 項目を更新します。

#### [](#ソース)ソース

```DataWeave
%dw 2.0
import * from dw::util::Values
output application/json
---
{name: "Mariano"} update "name" with "Data Weave"
```

#### [](#出力)出力

```Json
{
  "name": "Data Weave"
}
```

## [](#update2)update(Object, PathElement): Any

この ​`update`​ 関数は、指定された ​`PathElement`​ 値でオブジェクト項目を更新します。

この関数は、指定された項目と値を含む新しいオブジェクトを返します。

### [](#パラメーター-2)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>objectValue</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">更新するオブジェクト。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>fieldName</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">項目名を指定する ​<code>PathElement</code>​。</p></td>
</tr>
</tbody>
</table>

### [](#例-2)例

次の例では、オブジェクト ​`{name: "Mariano"}`​ の ​`name`​ 項目の値を更新します。これは ​`field("name")`​ を使用して ​`PathElement`​ を返し、それを ​`update`​ に渡します。​`with "Data Weave"`​ を使用して ​`name`​ の値 (​`Data Weave`​) を指定します。

#### [](#ソース-2)ソース

```DataWeave
%dw 2.0
import * from dw::util::Values
output application/json
---
{name: "Mariano"} update field("name") with "Data Weave"
```

#### [](#出力-2)出力

```Json
{
  "name": "Data Weave"
}
```

## [](#update3)update(Array, Number): Any

指定された値で配列インデックスを更新します。

この ​`update`​ 関数は、指定されたインデックスの値を変更する新しい配列を返します。

### [](#パラメーター-3)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">objectValue</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">更新する配列。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">indexToUpdate</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">更新する配列のインデックス。インデックスは数値である必要があります。</p></td>
</tr>
</tbody>
</table>

### [](#例-3)例

次の例では、入力配列 ​`[1,2,3]`​ 内の値 ​`2`​ (インデックスは ​`1`​) を ​`5`​ に置き換えます。

#### [](#ソース-3)ソース

```DataWeave
%dw 2.0
import * from dw::util::Values
output application/json
---
[1,2,3] update 1 with 5
```

#### [](#出力-3)出力

```Json
[
   1,
   5,
   3
 ]
```

## [](#update4)update(Array, String): Any

この ​`update`​ 関数は、指定された文字列値で、指定された配列内のすべてのオブジェクトを更新します。

### [](#パラメーター-4)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>objectValue</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">更新するオブジェクトの配列。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>indexToUpdate</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">更新する項目の名前を提供する文字列。</p></td>
</tr>
</tbody>
</table>

### [](#例-4)例

次の例では、オブジェクトの配列内の ​`role`​ 項目の値を更新します。

#### [](#ソース-4)ソース

```DataWeave
%dw 2.0
import * from dw::util::Values
output application/json
---
[{role: "a", name: "spiderman"}, {role: "b", name: "batman"}] update "role" with "Super Hero"
```

#### [](#出力-4)出力

```Json
[{
   "role": "Super Hero",
   "name": "spiderman"
 },
 {
   "role": "Super Hero",
   "name": "batman"
}]
```

## [](#update5)update(Array, PathElement): Any

この ​`update`​ 関数は、指定された ​`PathElement`​ 値で、指定された配列のインデックスを更新します。

この関数は、指定されたインデックスの位置に指定された値が含まれる新しい配列を返します。

### [](#パラメーター-5)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>objectValue</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">更新する配列。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>indexToUpdate</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">更新する配列のインデックス。インデックスは ​<code>PathElement</code>​ として指定する必要があります。</p></td>
</tr>
</tbody>
</table>

### [](#例-5)例

次の例では、入力配列内の要素の値を更新します。これは ​`index(1)`​ を使用してインデックスを ​`PathElement`​ として返し、それを ​`update`​ に渡します。このインデックスの位置にある値 ​`2`​ を ​`5`​ に置き換えます。

#### [](#ソース-5)ソース

```DataWeave
%dw 2.0
import * from dw::util::Values
output application/json
---
[1,2,3] update index(1) with 5
```

#### [](#出力-5)出力

```Json
[
   1,
   5,
   3
 ]
```

## [](#update6)update(Array | Object | Null, Array<String | Number | PathElement>): Any

指定された値で、指定されたパスの位置にある値を更新します。

### [](#パラメーター-6)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>objectValue</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">更新する値。配列、オブジェクト、または null 値を受け入れます。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>path</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">更新するパス。パスは文字列、数値、または ​<code>PathElement</code>​ の配列である必要があります。</p></td>
</tr>
</tbody>
</table>

### [](#例-6)例

次の例では、ユーザーの名前を更新します。

#### [](#ソース-6)ソース

```DataWeave
%dw 2.0
import * from dw::util::Values
output application/json
---
{user: {name: "Mariano"}} update ["user", field("name")] with "Data Weave"
```

#### [](#出力-6)出力

```Json
{
   "user": {
     "name": "Data Weave"
   }
 }
```

## [](#update7)update(Null, Number | String | PathElement): Any

`update`​ を ​`null`​ 値に使用できるようにするヘルパー関数。