# Select first element in array

**URL:** <https://forum.ionicframework.com/t/select-first-element-in-array/154157>\
**Category:** ionic-v3\
**Created:** [January 25, 2019, 12:31pm UTC](https://forum.ionicframework.com/t/select-first-element-in-array/154157 "2019-01-25T12:31:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pettrin](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/pettrin/32/127292_2.png) [@pettrin](https://forum.ionicframework.com/u/pettrin)\
**Post date:** [January 25, 2019, 12:31pm UTC](https://forum.ionicframework.com/t/select-first-element-in-array/154157/1 "2019-01-25T12:31:24Z")

</div>

# [Select first element in array](https://pt.stackoverflow.com/questions/357989/pr%c3%a9-selecionar-primeiro-elemento-do-array)

**My Select**

```auto
 <ion-item>
   <ion-label floating color="primary" interface="popover">Opções de Parcelamento</ion-label>
   <ion-icon name="pricetags"></ion-icon>
   <ion-select class="myCustomSelect" [(ngModel)]="formaVezes" [ngModelOptions]="{standalone:true}">
     <ion-option *ngFor="let p of parcelamentosArray" [value]="p.type" [selected]="p.type[0]" > {{ p.value}} </ion-option>
  </ion-select>
</ion-item>

```

**My Array**

**console.log(this.parcelamentosArray);**

```auto
(8) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {type: "1"value: "1x de R$ 38,50 (sem juros)"}
1: {type: "2"value: "2x de R$ 20,12 - Total: R$ 40,24 (2.99% a.m)"}
2: {type: "3", value: "3x de R$ 13,61 - Total: R$ 40,82 (2.99% a.m)"}
3: {type: "4", value: "4x de R$ 10,36 - Total: R$ 41,42 (2.99% a.m)"}
4: {type: "5", value: "5x de R$ 8,40 - Total: R$ 42,02 (2.99% a.m)"}
5: {type: "6", value: "6x de R$ 7,11 - Total: R$ 42,63 (2.99% a.m)"}
6: {type: "7", value: "7x de R$ 6,18 - Total: R$ 43,24 (2.99% a.m)"}
7: {type: "8", value: "8x de R$ 5,48 - Total: R$ 43,86 (2.99% a.m)"}

```

what I can do for pre select this element first?

```auto
0: {type: "1"value: "1x de R$ 38,50 (sem juros)"}

```

---

<div class="post-metadata">

**Author:** ![abhayjani](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/abhayjani/32/121906_2.png) [@abhayjani](https://forum.ionicframework.com/u/abhayjani)\
**Post date:** [January 25, 2019, 12:53pm UTC](https://forum.ionicframework.com/t/select-first-element-in-array/154157/2 "2019-01-25T12:53:52Z")

</div>

there is only one small change.

```auto
<ion-option *ngFor="let p of parcelamentosArray" [value]="p.type" [selected]="p[0]" > {{ p.value}} </ion-option>

```

🙂

---

<div class="post-metadata">

**Author:** ![pettrin](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/pettrin/32/127292_2.png) [@pettrin](https://forum.ionicframework.com/u/pettrin)\
**Post date:** [January 25, 2019, 1:53pm UTC](https://forum.ionicframework.com/t/select-first-element-in-array/154157/4 "2019-01-25T13:53:43Z")

</div>

Of course your code is correctly, but still don’t working on my app

---

<div class="post-metadata">

**Author:** ![abhayjani](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/abhayjani/32/121906_2.png) [@abhayjani](https://forum.ionicframework.com/u/abhayjani)\
**Post date:** [January 25, 2019, 2:01pm UTC](https://forum.ionicframework.com/t/select-first-element-in-array/154157/5 "2019-01-25T14:01:10Z")

</div>

ok let do it in different way,  
in html file

```auto
<ion-option *ngFor="let p of parcelamentosArray" [value]="p.type" [selected]="p[0].type == temp" > {{ p.value}} </ion-option>

```

and in ts file

```auto
this.temp = parcelamentosArray[0].type

```

this is because selected take only boolean value either true or false.

---

<div class="post-metadata">

**Author:** ![pettrin](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/pettrin/32/127292_2.png) [@pettrin](https://forum.ionicframework.com/u/pettrin)\
**Post date:** [January 25, 2019, 4:12pm UTC](https://forum.ionicframework.com/t/select-first-element-in-array/154157/6 "2019-01-25T16:12:26Z")

</div>

Again give a [error](https://imgur.com/27mGkKs).  
If use `[selected]="parcelamentosArray[0].type == temp"` , works… But not in [correct](https://imgur.com/a/TvKfPWH) way.

---

<div class="post-metadata">

**Author:** ![abhayjani](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/abhayjani/32/121906_2.png) [@abhayjani](https://forum.ionicframework.com/u/abhayjani)\
**Post date:** [January 25, 2019, 4:14pm UTC](https://forum.ionicframework.com/t/select-first-element-in-array/154157/7 "2019-01-25T16:14:08Z")

</div>

what exact error you got?

---

<div class="post-metadata">

**Author:** ![pettrin](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/pettrin/32/127292_2.png) [@pettrin](https://forum.ionicframework.com/u/pettrin)\
**Post date:** [January 25, 2019, 4:14pm UTC](https://forum.ionicframework.com/t/select-first-element-in-array/154157/8 "2019-01-25T16:14:50Z")

</div>

See in the link! [error](https://imgur.com/27mGkKs) .
