Work out if a string is "fieldname" or "tablename.fieldname", and assign variables Is there a neater way to write this code?

    var table, field, dbFieldEntries;
    var s = 'one.two';
    // The DB field is always the first parameter
    dbFieldEntries = s.split( '.' );
    if( dbFieldEntries.length === 1 ){
      field = dbEntryEntries[ 0 ];
    } else {
      table = dbEntryEntries[ 0 ];
      field = dbEntryEntries[ 1 ];
    }


Basically, s can be either something or something.other.
If it's something, then table is undefined and field is something; it it's something.other, then table is something and field is other.
Assuming that field always gets the value of the last part of dbFieldEntries you could do:

field = dbEntryEntries[ dbFieldEntries.length - 1 ];
if ( dbFieldEntries.length &gt; 1 ) {
  table = dbEntryEntries[ 0 ];
}


Besides this, s is a bad variable name.