JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" value="yay-1">
<input type="text" value="yay-2">
<input type="text" value="yay-3">
<input type="text" value="">
<input type="text" value="">
JavaScript
$(function() {
$( "input" ).val(function( i, val ) {
// Ternary if statement.
// In the console: Show index of each input that is not empty.
val && console.log('not empty: input-' + i );
// Still ternary if statement.
// Gives each input a border.
val && $(this).css({ border: '1px solid red' });
// Normal if statement.
// Gives each input a new class with its own index numer.
if ( val ) { $(this).addClass( 'input-' + (++i) ); }
// If value is not empty, return the value.
// If value is empty, return the text string.
val = val ? val : "I'm empty inside :(";
// Note that you don't have to return val if you don't want to, it's just for show in this case.
return val
});
});