-2

Have anybody an idea, how I can split these in Typescript or JS:

{ "AED": "United Arab Emirates Dirham", "AFN": "Afghan Afghani", "ALL": "Albanian Lek" }

I want only the names like this:

AED AFN ALL

  • Possible duplicate of [How do I split a string with multiple separators in javascript?](https://stackoverflow.com/questions/650022/how-do-i-split-a-string-with-multiple-separators-in-javascript) – Kasnady Feb 17 '18 at 03:29

2 Answers2

0

you are doing it wrong, first of all modify your object to array of objects like below

let currencies = [
  {
    code: "AED",
    fullName: "United Arab Emirates Dirham"

  },
  {
    code: "AFN",
    fullName: "Afghan Afghani"

  },
  {
    code: "ALL",
    fullName: "Albanian Lek"

  }
];

now you can traverse through it like

currencies.forEach(val => {
  //use val.code to get desired currencies codes
})
Imdad Ali
  • 727
  • 1
  • 8
  • 18
0

You can use Object.keys (link) to extract all keys from some object.

var countries = { "AED": "United Arab Emirates Dirham", "AFN": "Afghan Afghani", "ALL": "Albanian Lek" }
var codes = Object.keys( countries );
console.log( codes ); // [ "AED", "AFN", "ALL" ]
Vlada
  • 1,653
  • 19
  • 23