Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react'
- let i = 0
- class Random extends Component {
- constructor(props) {
- super(props)
- this.state = {
- elementIndex : 0
- }
- }
- hello = () => {
- let arr = ["1st", "2nd", "3rd", "4rth", "5th", "6th"]
- this.setState({
- elementIndex: arr[i]
- })
- if(i > arr.length - 1){
- this.setState ({
- elementIndex: "Array is full"
- })
- }
- i++
- }
- render() {
- return (
- <div>
- <h1>Array Element: {this.state.elementIndex}</h1>
- <button onClick = {this.hello}>Click me</button>
- </div>
- )
- }
- }
- export default Random
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement