Question: I have data in multiple vectors that I would like to convert to a data.frame with one ID column (vector name) and one data column (vector values). Here's a toy example:

```
data.1 <- c(1, 2)
data.2 <- c(10, 20, 30)
df <- bind_rows(data.frame(ID="data.1", value=data.1), data.frame(ID="data.2", value=data.2))

```

If I have another vector (or any other data structure) that contains the name of the variables as a character string, how can I elegantly shorten the code? One time I would need to retrieve the entry as a character string (for ID) and the other time as the variable name (for value).

```
studies <- c("data.1", "data.2")

```

Answer: 
```js
var jsonObj = [{"Product":"7318802U","Amount":"5"},{"Product":"7304773U","Amount":"1"}];

var Products = ["7318802U","7304773U","7212UCSS"];

for(var i = 0; i<Products.length; i++) {
  let targetObj = jsonObj.find((v) => v.Product === Products[i]);
  if (targetObj) {
    console.info(Products[i] + " exist")
    console.info("Amount: " + targetObj.Amount);
  } else {
    console.info(Products[i] + " not exist")
    console.info("Amount: 0");
  }
}
```
```js
var txt = [{
  "Product": "7318802U",
  "Amount": "5"
}, {
  "Product": "7304773U",
  "Amount": "1"
}];

var jsonObj = txt;

var Products = ["7318802U", "7304773U", "7212UCSS"];

function _isContains(json, value) {
  let contains = false;
  Object.keys(json).some(key => {
    contains = typeof json[key] === 'object' ? _isContains(json[key], value) : json[key] === value;
    return contains;
  });
  return contains;
}

for (var i = 0; i < Products.length; i++) {
  if (_isContains(jsonObj, Products[i])) {
    console.info(Products[i] + " exist");
    console.info("Amount: " + txt.find(v => v['Product'] === Products[i])['Amount']);

  } else {
    console.info(Products[i] + " not exist")
    console.info("Amount: 0")
  }
}
```