congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo For Javascript
String.lastIndexOf
Code IndexAdd Tabnine to your IDE (free)

How to use
lastIndexOf
function
in
String

Best JavaScript code snippets using builtins.String.lastIndexOf(Showing top 15 results out of 2,763)

origin: shen100/mili

const extName = (urlStr: string) => {
  let ext = '';
  const index = urlStr.lastIndexOf('.');
  if (index >= 0) {
    ext = urlStr.substr(index);
  }
  return ext;
}
origin: withspectrum/spectrum

const truncateString = (str: string, length: number) => {
 if (str.length <= length) {
  return str;
 }
 const subString = str.substr(0, length);
 return subString.substr(0, subString.lastIndexOf(' ')) + '…';
}
origin: microsoft/botframework-sdk

private updateVersionValue(versionId: string) {
  let numberVersionId = parseFloat(versionId)
  if (isNaN(numberVersionId)) {
   const index = versionId.lastIndexOf('-')
   if (index > 0) {
    const strVersion = versionId.substring(0, index)
    const numberVersion = versionId.substring(index + 1)
    numberVersionId = parseFloat(numberVersion)
    if (isNaN(numberVersionId)) {
     return versionId
    } else {
     const newVersionId = numberVersionId + 0.1

     return strVersion + '-' + newVersionId.toFixed(1)
    }
   } else {
    return versionId + '-0.1'
   }
  } else {
   return (numberVersionId + 0.1).toFixed(1)
  }
 }
origin: strapi/strapi

/**
 * Parse single where param
 * @param {string} whereClause - Any possible where clause e.g: id_ne text_ncontains
 * @param {string} value - the value of the where clause e.g id_ne=value
 */
const convertWhereClause = (whereClause, value) => {
 const separatorIndex = whereClause.lastIndexOf('_');

 // eq operator
 if (separatorIndex === -1) {
  return { field: whereClause, value };
 }

 // split field and operator
 const field = whereClause.substring(0, separatorIndex);
 const operator = whereClause.slice(separatorIndex + 1);

 if (BOOLEAN_OPERATORS.includes(operator) && field === '') {
  return { field: null, operator, value: [].concat(value).map(convertWhereParams) };
 }

 // the field as underscores
 if (!VALID_REST_OPERATORS.includes(operator)) {
  return { field: whereClause, value };
 }

 return { field, operator, value };
}
origin: strapi/strapi

const name = decodeURIComponent(url.pathname.substring(url.pathname.lastIndexOf('/') + 1));
const CancelToken = axios.CancelToken;
const abortController = new AbortController();
origin: GoogleChromeLabs/ndb

/**
  * @param {string} fileURL
  * @param {string} newName
  */
 renameFile(fileURL, newName) {
  const newURL = new URL(fileURL.substr(0, fileURL.lastIndexOf('/') + 1) + newName);
  try {
   if (fs.existsSync(newURL)) return false;
   fs.renameSync(new URL(fileURL), newURL);
   return true;
  } catch (e) {
   return false;
  }
 }
origin: Automattic/wp-calypso

/**
   * Renders the text section of the tweet.
   *
   * @param {string} text The text of the tweet.
   * @param {Array} urls Optional. An array of URLs that are in the text.
   * @param {object} card Optional. The card data for this tweet.
   *
   * @returns {React.Element} The text section.
   */
  renderText( text, urls = [], card = {} ) {
    // If the text ends with the card URL, remove it.
    const cardUrl = card.url || '';
    const deCardedText = text.endsWith( cardUrl )
      ? text.substr( 0, text.lastIndexOf( cardUrl ) )
      : text;

    const __html = urls.reduce(
      ( html, url ) =>
        html.replace( new RegExp( '\\(' + url + '\\)', 'g' ), `(<a href="${ url }">${ url }</a>)` ),
      stripHtmlTags( deCardedText ).replace( new RegExp( '\\n', 'g' ), '<br/>' )
    );

    // We can enable dangerouslySetInnerHTML here, since the text we're using is stripped
    // of all HTML tags, then only has safe tags added in createTweetMarkup().
    /* eslint-disable react/no-danger */
    return <div className="twitter-preview__text" dangerouslySetInnerHTML={ { __html } } />;
    /* eslint-enabled react/no-danger */
  }
origin: sx1989827/DOClever

var index=path.lastIndexOf(pathLib.sep);
index=path.lastIndexOf(pathLib.sep,index-1);
var dbPath=path.substring(index).replace(/\\/g,"/");
var pipe=stream.pipe(fs.createWriteStream(path));
origin: moleculerjs/moleculer

if (len == 2 && firstStarPosition == 0 && pattern.lastIndexOf("*") == 1) {
  return true;
origin: standard-things/esm

 this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1
 this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length
} else {
origin: Automattic/wp-calypso

/**
 * Check to see if we should transpile certain files in node_modules
 *
 * @param {string} filepath the path of the file to check
 * @returns {boolean} True if we should transpile it, false if not
 *
 * We had a thought to try to find the package.json and use the engines property
 * to determine what we should transpile, but not all libraries set engines properly
 * (see d3-array@2.0.0). Instead, we transpile libraries we know to have dropped Node 4 support
 * are likely to remain so going forward.
 */
function shouldTranspileDependency( filepath ) {
  // find the last index of node_modules and check from there
  // we want <working>/node_modules/a-package/node_modules/foo/index.js to only match foo, not a-package
  const marker = '/node_modules/';
  const lastIndex = filepath.lastIndexOf( marker );
  if ( lastIndex === -1 ) {
    // we're not in node_modules
    return false;
  }

  const checkFrom = lastIndex + marker.length;

  return nodeModulesToTranspile.some( ( modulePart ) =>
    filepath.startsWith( modulePart, checkFrom )
  );
}
origin: avwo/whistle

var dashIndex = filename.lastIndexOf('_');
if (dashIndex <= 0) {
 return;
origin: Automattic/wp-calypso

/**
 * Parse the tld from a given domain name, semi-naively. The function
 * first parses against a list of tlds that have been sold on WP.com
 * and falls back to a simplistic "everything after the last dot" approach
 * if the list of explicitly allowed tlds failed. This is ultimately not comprehensive as that
 * is a poor base assumption (lots of second level tlds, etc). However,
 * for our purposes, the approach should be "good enough" for a long time.
 *
 * @param {string}     domainName     The domain name parse the tld from
 * @returns {string}                   The TLD or an empty string
 */
export function getTld( domainName ) {
  const lastIndexOfDot = domainName.lastIndexOf( '.' );

  if ( lastIndexOfDot === -1 ) {
    return '';
  }

  let tld = parseDomainAgainstTldList( domainName, wpcomMultiLevelTlds );

  if ( ! tld ) {
    tld = domainName.substring( lastIndexOfDot + 1 );
  }

  return tld;
}
origin: strapi/strapi

/**
 * Parse single where param
 * @param {string} whereClause - Any possible where clause e.g: id_ne text_ncontains
 * @param {string} value - the value of the where clause e.g id_ne=value
 */
const convertWhereClause = (whereClause, value) => {
 const separatorIndex = whereClause.lastIndexOf('_');

 // eq operator
 if (separatorIndex === -1) {
  return { field: whereClause, value };
 }

 // split field and operator
 const field = whereClause.substring(0, separatorIndex);
 const operator = whereClause.slice(separatorIndex + 1);

 if (BOOLEAN_OPERATORS.includes(operator) && field === '') {
  return { field: null, operator, value: [].concat(value).map(convertWhereParams) };
 }

 // the field as underscores
 if (!VALID_REST_OPERATORS.includes(operator)) {
  return { field: whereClause, value };
 }

 return { field, operator, value };
}
origin: strapi/strapi

const name = decodeURIComponent(url.pathname.substring(url.pathname.lastIndexOf('/') + 1));
const CancelToken = axios.CancelToken;
const abortController = new AbortController();
builtins(MDN)StringlastIndexOf

JSDoc

Returns the last occurrence of a substring in the string.

Most used builtins functions

  • Console.log
  • Console.error
  • Promise.then
    Attaches callbacks for the resolution and/or rejection of the Promise.
  • Promise.catch
    Attaches a callback for only the rejection of the Promise.
  • Array.push
    Appends new elements to an array, and returns the new length of the array.
  • Array.length,
  • Array.map,
  • String.indexOf,
  • fetch,
  • Window.location,
  • Window.addEventListener,
  • ObjectConstructor.keys,
  • Array.forEach,
  • Location.reload,
  • Response.status,
  • Navigator.serviceWorker,
  • ServiceWorkerContainer.register,
  • ServiceWorkerRegistration.installing,
  • ServiceWorkerContainer.controller

Popular in JavaScript

  • superagent
    elegant & feature rich browser / node HTTP with a fluent API
  • request
    Simplified HTTP request client.
  • minimatch
    a glob matcher in javascript
  • mongodb
    The official MongoDB driver for Node.js
  • postcss
  • express
    Fast, unopinionated, minimalist web framework
  • q
    A library for promises (CommonJS/Promises/A,B,D)
  • js-yaml
    YAML 1.2 parser and serializer
  • aws-sdk
    AWS SDK for JavaScript
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJavascript Code Index
Get Tabnine for your IDE now