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: 
```js
var array1 = [
  {
    course: "ABC",
    skills:["skill1", "skill2"]
  },
  {
    course: "DEF",
    skills: ["skill1"]
  },
  {
    course: "GHI",
    skills: ["skill1", "skill2", "skill3"]
  }
];

const flatten = array =>
  array.reduce((results, item) => [...results, ...item.skills.map(skill => ({ course: item.course, skill: skill }))], []);

console.log(flatten(array1));
```
You can do it by using two `forEach`. In the first `forEach` loop the outer array and in the inner `forEach` iterate the skills array and create an object using each element from the `skills` array

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

let newArr = [];
array1.forEach(function(item) {

  item.skills.forEach(function(elem) {
    newArr.push({
      course: item.course,
      skill: elem
    })
  })
});
console.log(newArr)
```