Question: I create some code to find AccessibilityId after swipe action, but it did "not" go into my while condition. ***How to make condition to find AccessibilityId?***

This is scenario I want.

```
1.Launch app, there is no test1_action buttons (AccessibilityId = test1_action)
2.To Click test1_action, will repeat swipe "i" times till find AccessibilityId.
3.After "i" times swiping, if there will be test1_action button then it will click it

```

iOS/iPhone/Appium

```
WebDriverWait wait = new WebDriverWait(driver, 20);
int i = 0;
while 
(!driver.findElement(MobileBy.AccessibilityId("test1_action")).isDisplayed()) {
    swipe(331, 544, 50, 544, 2);
    i++;
        }
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("test1_action"))).click();

```

When i run this, I faced below error

> 
> Caused by: org.openqa.selenium.NoSuchElementException: An element
>  could not be located on the page using the given search parameters.
> 
> 
>

Answer: 
You can do this with [`flatMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap) (if it's supported where you're running your code). The idea is to map each course, and then further map each skill to the object you want and then flatten it:

```js
var array1 = [{
    "course": "ABC",
    "skills": ["skill1", "skill2"]
  },
  {
    "course": "DEF",
    "skills": ["skill1"]
  },
  {
    "course": "GHI",
    "skills": ["skill1", "skill2", "skill3"]
  }
];

var res = array1.flatMap(({course, skills}) => skills.map(skill => ({course, skill})));
console.log(res);
```
You can do this using `map` function of array object. `map` traverse through each element.

```js
var array1 = [
  {
    "course": "ABC",
    "skills":["skill1", "skill2"],
  },
  {
    "course": "DEF",
    "skills":["skill1"],
  },
  {
    "course": "GHI",
    "skills":["skill1", "skill2", "skill3"],
  }
];

let mappedArray = [];

array1.map(el=>{
  el.skills.map(skill=>{
    mappedArray.push({
      course: el.course,
      skill: skill
    });
  });
});

console.log(mappedArray);
```