teleren/devto huggingface dataset:
Laravel/Vue.js simple form submission using Vue components.
Tags: laravel, vue
Published: 2021-03-22 02:32:24

Vue is a progressive framework for building user interfaces, if you used any recent version of Laravel you might have noticed it’s standard bundled in Laravel. I’m going to show you a simple, yet efficient way to submit a form using Vue.js.

For this article, I’m using Laravel 5.6. To install Laravel visit: https://laravel.com/docs/5.6#installation.

We’ll start by heading over to the folder 
/resources/assets/js/components notice that there’s a ExampleComponent.vue already included. When you head over to /resources/assets/js/app.js you should see the file being registered to Vue as a component. Also notice that that Vue is instantiated beneath it, it wraps around an element with the ID ‘app’. It’s good to know that we can of course only use Vue inside this element.

So.. Let’s say you want to use the example component. Then you’ll simply add this html element <example-component></example-component> in your html. Just make sure that it’s inside the wrapper with the ID ‘app’.

To avoid any mistakes, when editing your Components, Javascript or SCSS files. Don’t forget to run ‘npm run dev’ or better, keep it running using ‘npm run watch’.

Inside /resources/assets/js/components we create a new component file, I’ll name it ‘ContactForm.vue’, since I’ll be creating.. a contact form obviously.

Inside our component file ContactForm.vue we’re going to add the HTML template part. Just like you would in a blade file, just wrapped inside <template>, like this:

*<template>
    <form>
        <div class="form-group">
            <label for="name">Name</label>
            <input type="text" class="form-control" name="name" id="name" />
        </div>

        <div class="form-group">
            <label for="email">E-mail</label>
            <input type="email" class="form-control" name="email" id="email" />
        </div>

        <div class="form-group">
            <label for="message">Message</label>
            <textarea class="form-control" name="message" id="message" rows="5"></textarea>
        </div>

        <button type="submit" class="btn btn-primary">Send message</button>
    </form>
</template>*

[Read Full Blog )Here](https://medium.com/@mscherrenberg/laravel-5-6-vue-js-simple-form-submission-using-components-92b6d5fd4434
Método findIndex - JavaScript
Tags: javascript, tutorial, webdev, beginners
Published: 2021-03-22 02:23:49

O método **findIndex()** retorna o **índice** do primeiro elemento no array que satisfazer a função de teste provida. Caso contrário será retornado -1, indicando que nenhum elemento passou no teste.

---

## **Parâmetros**

**callback -** Função passada como referência, será executada a cada iteração do array. Esta função pode receber 3 argumentos.

&emsp; **element -** O elemento que está sendo processado no array. 

&emsp; **index -** O índice do elemento atual que está sendo processado no array. (Opcional)

&emsp; **array -** O array para qual **findIndex** foi chamada. (Opcional)

---

### Sintaxe

```jsx
const elementIndex = numbers.findIndex(functionCallback);
```

---

## **Retorno**

O método **findIndex()** retorna o **índice** do primeiro elemento que passou no teste da função provida. Se nenhum elemento satisfazer retornará **-1** indicando que nenhum elemento passou no teste.

---

## Exemplos

Retorna o índice do elemento que tem o valor igual **19**

```jsx
const numbers = [10, 6, 8, 19, 18, 20];
function checkNumber(value) {
	return value === 19;
}

const elementIndex = numbers.findIndex(checkNumber);
// elementIndex -> 3
```

Retorna o índice do elemento que tem o valor igual **40**, mas neste caso retorna -1 porque não existe esse valor no array.

```jsx
const numbers = [10, 6, 8, 19, 18, 20];
function checkNumber(value) {
	return value === 40;
}

const elementIndex = numbers.findIndex(checkNumber);
// elementIndex -> -1
```

<a href="https://www.notion.so/elianbecali/findIndex-5f95ae80ba7942ac80fe919c690a4c4d" target="_blank">Método findindex | Notion
</a>
<a href="https://www.youtube.com/watch?v=25DSz7ckESE" target="_blank">Método findindex | Youtube
</a>
Método find - JavaScript
Tags: javascript, tutorial, webdev, beginners
Published: 2021-03-22 02:12:29

O método **find()** retorna o valor do primeiro elemento do array que satisfazer a função de teste provida. Caso contrário será retornado undefined.

---

## **Parâmetros**

**callback -** Função passada como referência, será executada a cada iteração do array. Esta função pode receber 3 argumentos.

&emsp; **element -** O elemento que está sendo processado no array. 

&emsp; **index -** O índice do elemento atual que está sendo processado no array. (Opcional)

&emsp; **array -** O array para qual **find** foi chamada. (Opcional)

---

### Sintaxe

```jsx
const approvedNumber= numbers.find(functionCallback);
```

---

## **Retorno**

O método **find()** retorna o valor do primeiro elemento que passou no teste da função provida.

---

## Exemplo

Retorna o valor do primeiro elemento que seja maior ou igual 18

```jsx
const numbers = [10, 6, 8, 19, 18, 20];
function isBigEnough(value) {
	return value >= 18;
}

const approvedNumber = numbers.find(isBigEnough);
// approvedNumber -> 19
```

<a href="https://www.notion.so/elianbecali/find-6e1d1d69fbb142cea74b7ac8155e1493" target="_blank">Método find | Notion
</a>
<a href="https://www.youtube.com/watch?v=YUM8uzaP6-k" target="_blank">Método find | Youtube
</a>
How to Check if an Array Includes a Value in JavaScript?
Tags: beginners, javascript, webdev, programming
Published: 2021-03-22 02:08:03

**Check out my books on Amazon at https://www.amazon.com/John-Au-Yeung/e/B08FT5NT62**

**Subscribe to my email list now at http://jauyeung.net/subscribe/**


Checking if an array includes a value is something that we’ve to do often in a JavaScript app.

In this article, we’ll look at how to check if an array includes a given value in JavaScript.

### Array.prototype.includes

The `includes` method is a method that’s included with the array instance.

It takes a value and compares it with `===` to check if an element is included.

For instance, we can write:

```
console.log(['apple', 'orange', 'grape'].includes('orange'));
```

If it’s included, then it returns `true` .

Otherwise, it returns `false` .

### Array.prototype.indexOf

We can also use the `indexOf` method of an array instance to check if it includes a given element.

It also uses `===` for comparison.

And it returns the index of the first instance of an item if it exists.

Otherwise, it returns -1.

To use it, we write:

```
console.log(['apple', 'orange', 'grape'].indexOf('orange') >= 0);
```

### Write Our Own

We can write our own function to search for a value.

For instance, we can write:

```
function contains(a, obj) {
  let i = a.length;
  while (i--) {
    if (a[i] === obj) {
      return true;
    }
  }
  return false;
}

console.log(contains(['apple', 'orange', 'grape'] , 'orange'));
```

We create the `contains` function that uses a `while` loop to search for an item.

If `a[i]` has the same value as `obj` then we return `true` .

If we loop through the whole `a` array and didn’t find anything that matches, then we return `false` .

### Array.prototype.some

The `some` method is another array instance method that comes with JavaScript arrays.

It lets us pass in a callback to check if any items match the given condition.

For instance, we can write:

```
const items = [{
  a: '1'
}, {
  a: '2'
}, {
  a: '3'
}]

console.log(items.some(item => item.a === '3'))
```

We have an `items` array that has a bunch of objects.

And we call `items.some` with a callback to check if any `items` entry with `a` property equal to 3 exists.

`some` returns `true` if an item that matches the given condition exists and `false` otherwise.

### Conclusion

There’re many ways to find if an array item exists in JavaScript.
How to Get a Timestamp in JavaScript?
Tags: javascript, webdev, programming, beginners
Published: 2021-03-22 02:07:44

**Check out my books on Amazon at https://www.amazon.com/John-Au-Yeung/e/B08FT5NT62**

**Subscribe to my email list now at http://jauyeung.net/subscribe/**


A UNIX timestamp is the number of seconds since January 1, 1970 midnight UTC.

It’s often used so that we can do calculations with time easily.

In this article, we’ll look at how to get the UNIX timestamp from a date object in JavaScript.

### The + Operator

We can use the `+` operator to convert the date object right to a UNIX timestamp.

For instance, we can write:

```
+new Date()
```

The `+` operator before the date object triggers the `valueOf` method in the `Date` object to return the timestamp as a number.

### The getTime Method

We can call `getTime` to do the same thing.

For instance, we can write:

```
new Date().getTime()
```

to return the UNIX timestamp of a date.

### Date.now Method

`Date.now` is a static method of the `Date` constructor that lets us get the current date-times timestamp.

For instance, we can write:

```
Date.now()
```

The timestamp is returned in milliseconds, so we have to divide it by 1000 and round it to get the timestamp in seconds.

To do that, we write:

```
Math.floor(Date.now() / 1000)
```

`Math.floor` rounds the number down to the nearest integer.

We can also round it with `Math.round` by writing:

```
Math.round(new Date().getTime() / 1000);
```

### Number Function

The `Number` function is a global function that lets us convert a non-number object or primitive value to a number.

And we can use it to convert a date to a timestamp.

To do that, we write:

```
Number(new Date())
```

Then we get the timestamp in seconds returned since it triggers the `valueOf` method of the `Date` instance like the `+` operator.

### Lodash _.now Method

Lodash also has a `now` method that returns the current timestamp.

To use it, we write:

```
_.now();
```

It’ll also return the current date’s timestamp.

### Conclusion

There’re many ways to get the timestamp of the current date and time or the date-time that we want with JavaScript.
How to Replace All Occurrences of a Javascript String?
Tags: webdev, programming, javascript, beginners
Published: 2021-03-22 02:07:25

**Check out my books on Amazon at https://www.amazon.com/John-Au-Yeung/e/B08FT5NT62**

**Subscribe to my email list now at http://jauyeung.net/subscribe/**


Replacing all occurrences of a string is something that we often have to do in a JavaScript app.

In this article, we’ll look at how to replace all occurrences of a string in a JavaScript app.

### String.prototype.replaceAll

The `replaceAll` method is a new method that’s available as part of JavaScript strings since ES2021.

It’s supported by many recent browsers like Chrome, Edge, or Firefox.

To use it, we write:

```
const result = "1 abc 2 abc 3".replaceAll("abc", "def");
```

The first argument is the string we want to replace.

And the 2nd argument is the string we want to replace it with.

Therefore, `result` is `'1 def 2 def 3'` .

### Split and Join

We can also split a string by the string that we want to replace and call `join` with the string that we want to replace the original string with,

For instance, we can write:

```
const result = "1 abc 2 abc 3".split("abc").join("def");
```

to split a string with `'abc'` as the separator and call `join` with `'def'` .

And we get the same result returned.

### Regex Replace

We can replace a string with the given pattern with a new string.

For instance, we can write:

```
const result = "1 abc 2 abc 3".replace(/abc/g, 'def');
```

to replace all instances `'abc'` with `'def'` .

The `g` flag means we look for all instances with the given pattern.

We can also use the `RegExp` constructor to create our regex object:

```
const result = "1 abc 2 abc 3".replace(new RegExp('abc', 'g'), 'def');
```

### While Loop and Includes

We can use the `includes` method to check if a string has a given substring.

So if it has a given substring, `includes` will return `true` .

Therefore, we can use it with the `while` loop to replace all instances of a substring with a new one by using `includes` in the condition.

For instance, we can write:

```
let str = "1 abc 2 abc 3";  
while (str.includes("abc")) {  
  str = str.replace("abc", "def");  
}
```

We use `let` so that we can reassign the value.

The only downside is that we have to mutate the `str` variable.

### Conclusion

There are many ways to replace all instances of a substring with another one in JavaScript.

The newest and easier way to replace all substrings is to use the `replaceAll` method, which comes with ES2021 and is available with most recent browsers.
How to Compare Two Dates with JavaScript?
Tags: webdev, programming, javascript, beginners
Published: 2021-03-22 02:07:02

**Check out my books on Amazon at https://www.amazon.com/John-Au-Yeung/e/B08FT5NT62**

**Subscribe to my email list now at http://jauyeung.net/subscribe/**

Comparing 2 dates is something we’ve to do often in a JavaScript app.

In this article, we’ll look at how to compare 2 dates with JavaScript.

### Comparing Timestamps

One easy way to compare 2 dates is to compare their timestamps.

We can get the timestamp with the `getTime` method.

For instance, we can write:

```
const d1 = new Date();  
const d2 = new Date(d1);  
const same = d1.getTime() === d2.getTime();  
const notSame = d1.getTime() !== d2.getTime();
```

`getTime` returns the UNIX epoch in seconds.

It’s time number of seconds since January 1, 1970 midnight UTC.

We can also write:

```
const d1 = new Date();  
const d2 = new Date(d1);  
const same = +d1 === +d2;  
const notSame = +d1 !== +d2;
```

which replaces `getTime` with the `+` before the date objects.

It does the same thing as `getTime` .

### Relational Operators

We can use relational operators directly with date objects.

For instance, we can write:

```
const d1 = new Date(2021, 0, 1);  
const d2 = new Date(2021, 0, 2);  
d1 < d2;  
d1 <= d2;  
d1 > d2;  
d1 >= d2;
```

to compare them directly with the relational operators.

`d1` and `d2` will be converted to timestamps before comparing.

### Subtracting Dates

We can also subtract one date from another and compare the result to what we want.

For instance, we can write:

```
const d1 = new Date(2021, 0, 1);  
const d2 = new Date(2021, 0, 2);  
console.log(d1 - d2 === 0);  
console.log(d1 - d2 < 0);  
console.log(d1 - d2 > 0);
```

This works because `d1` and `d2` are converted to timestamps before we subtract them.

### Comparing Year, Month, and Date

We can compare the year, month, and day of 2 date objects to check if they’re the same to determine if they’re the same date.

For instance, we can write:

```
const d1 = new Date(2021, 0, 1);  
const d2 = new Date(2021, 0, 2);  
const isSameDate = d1.getFullYear() === d2.getFullYear() &&  
  d1.getDate() === d2.getDate() &&  
  d1.getMonth() === d2.getMonth();
```

`getFullYear` returns the 4 digit year number.

`getDate` returns the date.

And `getMonth` returns the month from 0 to 11. 0 is January, 1 is February, etc.

### Conclusion

We can compare 2 dates easily with JavaScript by converting them to numbers with various operators.

Then we can compare them.

We can also compare their year, month, and day values individually.
How to Loop Over All Array Entries in JavaScript?
Tags: javascript, webdev, programming, beginners
Published: 2021-03-22 02:06:39

**Check out my books on Amazon at https://www.amazon.com/John-Au-Yeung/e/B08FT5NT62**

**Subscribe to my email list now at http://jauyeung.net/subscribe/**


Looping over all array entries is a common operation we do in JavaScript programs.

In this article, we’ll look at how to loop over all entries in a JavaScript array.

### `Array.prototype.forEach`

We can use a JavaScript instance's `forEach` method to loop through each entry of a JavaScript array.

For instance, we can write:

```
const a = ["a", "b", "c"];
a.forEach((entry) => {
  console.log(entry);
});
```

We call `forEach` on `a` with a callback that gets the array entry from the first parameter.

Then we can do whatever we want with it in the callback.

### `for` Loop

We can use a `for` loop to loop through all the items in a JavaScript array.

For instance, we can write:

```
const a = ["a", "b", "c"];
for (let index = 0; index < a.length; index++) {
  console.log(a[index]);
}
```

We set `index` to 0, and we set the max loop limit to `a.length` .

And we increment `index` by 1 in each iteration with `index++` .

Then in the loop body, we log `a[index]` to get the value of the `a` array entry with the given `index` .

Also, we can loop backward with:

```
const a = ["a", "b", "c"];
for (let index = a.length - 1; index >= 0; --index) {
  console.log(a[index]);
}
```

We start with `a.length` , end the loop when `index` is 0, and we decrement `index` by 1 in each iteration.

The loop body is the same.

### `for-of Loop`

Since ES6, we can use the for-of loop to loop through each array entry in our JavaScript code.

For instance, we can write:

```
const a = ["a", "b", "c"];
for (const val of a) {
  console.log(val);
}
```

`val` has the value we’re iterating through.

`a` is the array.

The for-of loop works with any iterable object like maps and sets in addition to arrays.

### Conclusion

We can loop through arrays with `forEach` , for loop, and for-of loop with JavaScript.
How to Check Whether a String Contains a Substring in JavaScript?
Tags: webdev, programming, javascript, beginners
Published: 2021-03-22 02:06:20

**Check out my books on Amazon at https://www.amazon.com/John-Au-Yeung/e/B08FT5NT62**

**Subscribe to my email list now at http://jauyeung.net/subscribe/**


Checking whether a string has another substring is a common operation we do in JavaScript programs.

In this article, we’ll look at how to check whether a string has another substring in JavaScript.

### String.prototype.includes

We can use the `includes` method that comes with string instances to check whether a string has a substring in JavaScript.

For instance, we can write:

```
const string = "foo";
const substring = "o";
console.log(string.includes(substring));
```

It returns `true` is the `substring` is in the `string` and `false` otherwise.

So this should return `true` .

We can also pass in a second argument with the index to start searching from.

So we can write:

```
console.log(str.includes('to be', 1))
```

to start searching `str` from index 1.

It’s included with ES6.

If we’re running a JavaScript program in an environment that doesn’t include ES6, we can add the following polyfill:

```
if (!String.prototype.includes) {
  String.prototype.includes = function(search, start) {
    'use strict';

    if (search instanceof RegExp) {
      throw TypeError('first argument must not be a RegExp');
    }
    if (start === undefined) { start = 0; }
    return this.indexOf(search, start) !== -1;
  };
}
```

### String.prototype.indexOf

Also, we can use the `indexOf` to get the first index of the substring in a string.

For instance, we can write:

```
const string = "foo";
const substring = "o";
console.log(string.indexOf(substring) !== -1);
```

If `indexOf` returns -1, then the `substring` isn’t in the `string` .

Otherwise, `substring` is in `string` .

### Conclusion

We can use the `indexOf` or `includes` method to check whether a JavaScript substring is in another string.
How to Redirect to Another Webpage in JavaScript?
Tags: webdev, programming, javascript, beginners
Published: 2021-03-22 02:05:59

**Check out my books on Amazon at https://www.amazon.com/John-Au-Yeung/e/B08FT5NT62**

**Subscribe to my email list now at http://jauyeung.net/subscribe/**


Redirecting to another webpage is a common operation we do in JavaScript programs.

In this article, we’ll look at how to redirect to a given URL with JavaScript.

### window.location.replace

One way to redirect to a given URL is to use the `window.location.replace` method.

For instance, we can write:

```
window.location.replace('https://yahoo.com')
```

We just pass in the URL in there.

`replace` doesn’t keep a record in the session history.

We can omit `window` since `window` is the global object:

```
location.replace('https://yahoo.com')
```

### window.location.href

We can also set the `window.location.href` property to the URL we want to go to.

For instance, we can write:

```
window.location.href = 'https://yahoo.com'
```

Setting `window.location.href` adds a record to the browser history, which is the same as clicking on a link.

Also, we can shorten this to `location.href` since `window` is global:

```
location.href = 'https://yahoo.com'
```

### window.location.assign

Also, we can call `window.location.assign` to navigate to the URL we want.

For instance, we can write:

```
window.location.assign('https://yahoo.com')
```

To navigate to `‘https://yahoo.com'` .

It also keeps a record in the browser history.

We can shorten this to `location.assign` since `window` is the global object:

```
location.assign('https://yahoo.com')
```

### Conclusion

There are a few ways to navigate to a URL in our JavaScript app.
How to Remove a Specific Element from a JavaScript Array?
Tags: javascript, webdev, programming, beginners
Published: 2021-03-22 02:05:41

**Check out my books on Amazon at https://www.amazon.com/John-Au-Yeung/e/B08FT5NT62**

**Subscribe to my email list now at http://jauyeung.net/subscribe/**


Removing an item from an array is a common operation we do in JavaScript programs.

In this article, we’ll look at how to remove a specific element from a JavaScript array.

### Splice

We can use the array’s `splice` method to remove an array item with the given index.

For instance, we can write:

```
const array = [1, 2, 3];
console.log(array);
const index = array.indexOf(2);
if (index > -1) {
  array.splice(index, 1);
}

console.log(array);
```

We have an `array` that we want to remove an item from.

We use the `indexOf` method to find the first index of the given item in the array.

If it returns anything other than -1, then the item is in the array.

And so if `index` isn’t -1, we call `splice` with the `index` and 1 to remove an item with the given index.

This works well with one entry and if we’re looking for a primitive value.

### Filter

We can also use the `filter` method to return the array without the given entry.

For instance, we can write:

```
const value = 3
let arr = [1, 2, 3, 4, 5]
arr = arr.filter(item => item !== value)
console.log(arr)
```

We look for `value` in `arr` and remove it by calling `filter` with a callback that returns `item !== value` .

This will keep anything in `arr` that has value other than `value` .

This will remove all entries with the given `value` so it’s more versatile than using `indexOf` and `splice` .

It also works with objects, which makes it more versatile.

`indexOf` doesn’t work with objects since we can’t specify the condition to look with a callback as we do with `filter` .

### Conclusion

We can remove items with the given condition easily from JavaScript arrays.
Nevertheless, Wolassa2-Mk7 Coded in 2021!
Tags: wecoded
Published: 2021-03-22 01:40:58

<!-- ✨Nevertheless,wolassa Mekonen coded in 2021 -->

## My most recent achievement was… thinking to start to learn java.

## Advocating for myself looks like… staying connected with my inteentions.

## My biggest goal is…

## My advice for allies to support underrepresented folks who code is...

<!-- Once your post is published, it will not appear on the /t/shecoded page until an admin approves it. This is an extra step to ensure there is no abuse on this important tag. --!>
9 Potensi Bangkit dari Kebangkrutan 
Tags: motivasi
Published: 2021-03-22 01:40:04

1.Kedisiplinan 2.Kerja Produktif, dll

Baca selengkapnya https://www.indidukasi.web.id/2021/02/9-potensi-bangkit-dari-kebangkrutan.html