Q:

Issue related to Dataweave

I need to append the data from responseLicensing (like expiryDate, cloudAccountName, cloudAccountId) to the responseSfdc data depending on the similar 'key' value.
Perform a lookup in the responseLicensing object using the key in an instance of responseSfdc and append some key-value pairs picked as a result of a successful lookup, to responseSfdc object.
%dw 2.0
output application/json 

var responseSfdc = [{
    "key": "SUBT00009925-1",
    "contractEndDate": null,
    "product": {
      "productName": "ArtPro+ Subscription",
      "productCode": "ArtPro+S",
      "downloadURL": null,
      "upgradeProduct": null
    },
    "projectReference": null,
    "orderNumber": "O-0000001105",
    "orderCreationDate": "2020-07-14T07:48:04.000Z",
    "subscriptionName": null,
    "autoRenewal": null
  },
  {
    "key": "SUBT00009925-2",
    "contractEndDate": null,
    "product": {
      "productName": "ArtPro+ Subscription",
      "productCode": "ArtPro+S",
      "downloadURL": null,
      "upgradeProduct": null
    },
    "projectReference": null,
    "orderNumber": "O-0000001105",
    "orderCreationDate": "2020-07-14T07:48:04.000Z",
    "subscriptionName": null,
    "autoRenewal": null
  }]

var responseLicensing = [{
    "key": "SUBT00009925-1",
    "expiryDate": "2021-01-16"
  },
  {
    "key": "SUBT00009925-2",
    "expiryDate": "2021-01-16",
    "cloudPublicName": "dodp-testcloud",
    "cloudAccountId": "a-t-1000-5001-0687-0024"
  }]
---
{
    responseSfdc map (sfdc,i) -> {
        
    }
}

Output I need is something like this -
[{
    "key": "SUBT00009925-1",
    "contractEndDate": null,
    "product": {
      "productName": "ArtPro+ Subscription",
      "productCode": "ArtPro+S",
      "downloadURL": null,
      "upgradeProduct": null
    },
    "projectReference": null,
    "orderNumber": "O-0000001105",
    "orderCreationDate": "2020-07-14T07:48:04.000Z",
    "subscriptionName": null,
    "autoRenewal": null,
    "expiryDate": "2021-01-16"
  },
  {
    "key": "SUBT00009925-2",
    "contractEndDate": null,
    "product": {
      "productName": "ArtPro+ Subscription",
      "productCode": "ArtPro+S",
      "downloadURL": null,
      "upgradeProduct": null
    },
    "projectReference": null,
    "orderNumber": "O-0000001105",
    "orderCreationDate": "2020-07-14T07:48:04.000Z",
    "subscriptionName": null,
    "autoRenewal": null,
    "expiryDate": "2021-01-16",
    "cloudPublicName": "dodp-testcloud",
    "cloudAccountId": "a-t-1000-5001-0687-0024"
  }]

A:

Another approach using function for readability and using default for safety check
%dw 2.0
output application/json 
var responseSfdc = [] // Assuming you have data for responseSfdc in array

var responseLicensing = [] // Assuming you have data for responseLicensing in an array

fun getLicenseInfo(key) = responseLicensing[?($.key == key)][0] 
---
responseSfdc map (item,index) -> (item) ++ 
  ((getLicenseInfo(item.key) default {}) - "key") 

"- key" is to remove the extra field from responseLicensing variable before appending it to the result.
"default {}" preventing the Null error. If you don't have match, the - key will fail and you will get an exception like:
You called the function '-' with these arguments: 
  1: Null (null)
  2: String ("key")

Another Option:
Using mergeWidth while checking the match, you don't need to use - to remove duplicate element.
Example:
%dw 2.0
import mergeWith from dw::core::Objects
var responseSfdc = []
var responseLicensing = []
output application/json 
---
responseSfdc map ((sfdc) -> sfdc mergeWith 
   responseLicensing[?($.key == sfdc.key)][0])

