Galaxy Wanderer Galaxy Wanderer - 2 months ago 8
Javascript Question

Set a variable value depending on value in a conditional variable

I need something like this

var String = "";
if (i == "Inbox") {var String = "Inbox"}
if (i == "Sent") {var String = "String"}

var showMailList = this.props.Data.String.map


I know it's simple question, but I can't find it in google. How can I achieve this?

Answer

Simply use the property with bracket notation

var showMailList = this.props.Data[ i ].map

i will your property Inbox or Sent