# Need help understanding what is going into this array..

**URL:** <https://forum.kirupa.com/t/need-help-understanding-what-is-going-into-this-array/635992>\
**Category:** Uncategorized\
**Created:** [February 14, 2017, 4:52am UTC](https://forum.kirupa.com/t/need-help-understanding-what-is-going-into-this-array/635992 "2017-02-14T04:52:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Baca](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/david_baca/32/7987_2.png) [@David\_Baca](https://forum.kirupa.com/u/David_Baca)\
**Post date:** [February 14, 2017, 4:52am UTC](https://forum.kirupa.com/t/need-help-understanding-what-is-going-into-this-array/635992/1 "2017-02-14T04:52:35Z")

</div>

trans[“amountDisplay”] = (type ==="withdrawal) ? “(” + amount + “)” : amount;

Code is from an Account Balance Calculator and I understand the other components added to the array trans but this one is busting my chops.

Thank you.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [February 14, 2017, 4:20pm UTC](https://forum.kirupa.com/t/need-help-understanding-what-is-going-into-this-array/635992/2 "2017-02-14T16:20:24Z")

</div>

There are a couple of things going on here. First, if trans is an array, what’s being “added” to it is not an array element. Instead, a property on the array object named “amountDisplay” is being set. This is equivalent to using `trans.amountDisplay = ...`.

Then the assignment is using the ternary operator. This is like a condensed if-else which returns one of two values depending on a condition

> **[Conditional (ternary) Operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator)**
>
> The conditional (ternary) operator is the only JavaScript operator that takes three operands. This operator is frequently used as a shortcut for the if statement.

Here, the condition is `(type ==="withdrawal")`. If that resolves to true, the value following the question mark (`?`) is returned, or `"(" + amount + ")"`. If it resolves to false, the value following the colon (`:`) is returned, or simply `amount`.

So basically, what you have here is the amountDisplay property of the trans object being set to either the value of amount, or the value of amount inside parens depending on whether or not type has a value of “withdrawal” or not.

---

<div class="post-metadata">

**Author:** ![David\_Baca](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/david_baca/32/7987_2.png) [@David\_Baca](https://forum.kirupa.com/u/David_Baca)\
**Post date:** [February 15, 2017, 2:13am UTC](https://forum.kirupa.com/t/need-help-understanding-what-is-going-into-this-array/635992/3 "2017-02-15T02:13:56Z")

</div>

Thank you. I thought it had to be some sort of if/else relationship but I was unfamiliar with the syntax.
